Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #47624 > unrolled thread

Re: "Don't rebind built-in names*" - it confuses readers

Started byTim Chase <python.list@tim.thechases.com>
First post2013-06-10 19:46 -0500
Last post2013-06-10 19:46 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: "Don't rebind built-in names*" - it confuses readers Tim Chase <python.list@tim.thechases.com> - 2013-06-10 19:46 -0500

#47624 — Re: "Don't rebind built-in names*" - it confuses readers

FromTim Chase <python.list@tim.thechases.com>
Date2013-06-10 19:46 -0500
SubjectRe: "Don't rebind built-in names*" - it confuses readers
Message-ID<mailman.3003.1370911490.3114.python-list@python.org>
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



[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web