Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #47624
| Date | 2013-06-10 19:46 -0500 |
|---|---|
| From | Tim Chase <python.list@tim.thechases.com> |
| Subject | Re: "Don't rebind built-in names*" - it confuses readers |
| References | <kp5q5o$fj1$1@ger.gmane.org> <CAMjeLr8X_M+zp1zkSGV_wUTyv_e6XCbfhpTmzVzy2t5PuONEjQ@mail.gmail.com> <CAMjeLr9w4iCFv=kgUdBTqgNgHpXh-AWGgxwR3tF=O=oX-DKtyA@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3003.1370911490.3114.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: "Don't rebind built-in names*" - it confuses readers Tim Chase <python.list@tim.thechases.com> - 2013-06-10 19:46 -0500
csiph-web