Sorta noob question - file vs. open?
Scott David Daniels
Scott.Daniels at Acm.Org
Tue Aug 23 18:52:40 EDT 2005
Peter A. Schott wrote:
> Been reading the docs saying that file should replace open in our code, but this
> doesn't seem to work:
This was really a misstatement; open is still preferred. file is now
a built in class, and its constructor is the same as open. I think the
current docs have been fixed.
> # Open file for writing, write something, close file
> MyFile = file("MyFile.txt", "w")
> MyFile.write("This is a test.")
> MyFile.close()
But you've given us no idea what went wrong.
> However, using:
> MyFile = open("MyFile.txt", "w")
> MyFile.write("This is a test.")
> MyFile.close()
I cannot help you if you don't tell me what went wrong.
Both bits of code seem to do the same thing for me.
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list