"Don't rebind built-in names*" - it confuses readers
Peter Otten
__peter__ at web.de
Tue Jun 11 03:09:32 EDT 2013
Terry Jan Reedy wrote:
> Many long-time posters have advised "Don't rebind built-in names*.
I'm in that camp, but I think this old post by Guido van Rossum is worth
reading to put the matter into perspective:
"""
> 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/)
"""
<http://mail.python.org/pipermail/python-dev/2004-July/045948.html>
More information about the Python-list
mailing list