[Python-Dev] file() or open()?
Skip Montanaro
skip at pobox.com
Wed Jul 7 18:09:02 CEST 2004
Guido> I recently saw a checkin that changed a call to open() into a
Guido> call to file(), suggesting that using file() is more "politically
Guido> correct" than open().
Guido> I'm not sure I agree with this. While open() and file() are
Guido> currently aliases for the same object, this may not always be the
Guido> case (it certainly wasn't always the case :-). In the future, I
Guido> could see open() become a factory function again that could
Guido> return an instance of a different class depending on the mode
Guido> argument, the default encoding for files, or who knows what; but
Guido> file will always remain a class.
That was probably a checkin I made. I would have left it alone except the
code was
file = open(...)
As long as I was changing the variable name to not mask the builtin I
changed the call as well. Had it been
f = open(...)
I probably would have kept my hands off.
In any case, I was under the impression that file() was the wave of the
future and open() a nod to the past.
Skip
More information about the Python-Dev
mailing list