[Python-Dev] file() or open()? (original) (raw)

Guido van Rossum guido at python.org
Wed Jul 7 18:53:01 CEST 2004


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.

Hm... I'm not particularly concerned over fixing all code that uses file as a local variable name, unless it actually is likely to need to reference the file class by name; builtins are in the last scope searched for the very reason that no programmer is expected to keep up with all additions to the built-in library, so locals hiding built-ins is okay. (Not that it isn't a good idea to avoid obvious clashes -- 'str' for string variables and 'type' for type variables being the most obvious stumbling blocks.)

In any case, I was under the impression that file() was the wave of the future and open() a nod to the past.

Now you know better...

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list