Sorta noob question - file vs. open?

Steve Holden steve at holdenweb.com
Tue Aug 23 20:03:10 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:
> 
> # Open file for writing, write something, close file
> MyFile = file("MyFile.txt", "w")
> MyFile.write("This is a test.")
> MyFile.close()
> 
> However, using:
> MyFile = open("MyFile.txt", "w")
> MyFile.write("This is a test.")
> MyFile.close()
> 
> I have no problems.
> 
> I'm sure that I'm missing something here about using open vs file, but am not
> sure what.  Probably just mis-read something.  If anyone can point me to what I
> didn't quite get, I'd appreciate the information.
> 
> Thanks.
> 
> -Pete

I can only assume you are using an older version of Python:

$ python
Python 2.4.1 (#1, May 27 2005, 18:02:40)
[GCC 3.3.3 (cygwin special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
  >>> open is file
True
  >>>

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC             http://www.holdenweb.com/




More information about the Python-list mailing list