"Don't rebind built-in names*" - it confuses readers
Tim Chase
python.list at tim.thechases.com
Mon Jun 10 20:46:40 EDT 2013
On 2013-06-10 17:20, Mark Janssen wrote:
> >> list = []
> >> Reading further, one sees that the function works with two
> >> lists, a list of file names, unfortunately called 'list',
> >
> > That is very good advice in general: never choose a variable name
> > that is a keyword.
>
> Btw, shouldn't it be illegal anyway? Most compilers don't let you
> do use a keyword as a variable name....
There's a subtle difference between a keyword and a built-in. Good
Python style generally avoids masking built-ins but allows it:
>>> "file" in dir(__builtins__)
True
>>> file = "hello" # bad style, but permitted
>>> print file
hello
Whereas the compiler prevents you from tromping on actual keywords:
>>> for = 4
File "<stdin>", line 1
for = 4
^
SyntaxError: invalid syntax
-tkc
More information about the Python-list
mailing list