block scope?

irstas at gmail.com irstas at gmail.com
Sat Apr 7 08:40:01 EDT 2007


On Apr 7, 6:48 am, James Stroud <jstr... at mbi.ucla.edu> wrote:
> Neal Becker wrote:
> > One thing I sometimes miss, which is common in some other languages (c++),
> > is idea of block scope.  It would be useful to have variables that did not
> > outlive their block, primarily to avoid name clashes.  This also leads to
> > more readable code.  I wonder if this has been discussed?
>
> Probably, with good code, block scope would be overkill, except that I
> would welcome list comprehensions to have a new scope:

Generator expressions have a new scope, and in Python 3.0 list
comprehensions will have one as well (according to http://www.python.org/dev/peps/pep-0289/
). It's a fix that might break existing code so it couldn't be
introduced in "minor" versions like 2.4 and 2.5.




More information about the Python-list mailing list