1 Replies - 330 Views - Last Post: 19 March 2013 - 05:52 PM Rate Topic: -----

#1 Midwest Product  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 74
  • Joined: 05-February 10

Method to open a file without passing any parameters (no filenames)

Posted 19 March 2013 - 05:48 PM

I need to write a method to open a file. Easy, right? I could do it like this, no problem.

f = open('myfile.txt')
for line in iter(f):
    print line
f.close()



However, the format that it needs to be called in is like this:

filename.myOpenFunction()



As you can see, the method does not accept any parameters. However, the open statement inside the method needs to know what the filename is! How can I get filename from filename.myOpenFunction() into the method?

Is This A Good Question/Topic? 0
  • +

Replies To: Method to open a file without passing any parameters (no filenames)

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8377
  • View blog
  • Posts: 31,144
  • Joined: 12-June 08

Re: Method to open a file without passing any parameters (no filenames)

Posted 19 March 2013 - 05:52 PM

I am guessing the object 'filename' has a property to be set for the file name.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1