[ANN] Python 2.4 Quick Reference available

Michael Hoffman cam.ac.uk at mh391.invalid
Sun Feb 20 07:43:49 EST 2005


David M. Cooke wrote:

> """
> The file() constructor is new in Python 2.2 and is an alias for
> open(). Both spellings are equivalent. The intent is for open() to
> continue to be preferred for use as a factory function which returns a
> new file object. The spelling, file is more suited to type testing
> (for example, writing "isinstance(f, file)").
> """

There was a discussion on python-dev (earlier this year IIRC) where
someone started changing the stdlib to use file() instead of open()
and the BDFL clarified what he originally wanted with file().

That said, I still use file() instead of open(). I think that:

for line in file("mytext.txt"):

makes a lot more sense than:

for line in open("mytext.txt"):

I guess it's because the first option sounds a lot more like English.

It's one of the few places where my personal style disagrees with
the "official" Python style but I just like file() so much better ;)
-- 
Michael Hoffman



More information about the Python-list mailing list