How would you open this file?

Bob bob.python at yahoo.com
Thu Feb 23 17:53:32 EST 2006


I want to open a file in a function and pass the file back to main so
another function can manipulate the file, something like this:

# begin
def open_file()
  filename=open(options.filename_input,'r')
  return filename

open_file()
print filename.read()
filename.close()
# end

But this doesn't work... It appears that "open_file()" needs a
variable, but in order to pass a variable to "open_file()" I first need
a variable... but I would rather have the function send me "filename"
without creating it main. Is that possible?

Is there a better way to have a function open a file and pass the file
back to main than what I am trying to do?  Thanks!




More information about the Python-list mailing list