[Python-Dev] Visibility scope for "for/while/if" statements
Guido van Rossum
guido at python.org
Fri Sep 23 04:38:54 CEST 2005
On 9/22/05, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Josiah Carlson wrote:
> > As for list comprehensions, they were literally meant to be a
> > completely equivalent translation of a set of for loops.
> I don't think that's quite true. I doubt whether anyone
> really thought about the issue when LCs were first being
> discussed. I didn't, but if I had, I wouldn't have
> considered the variable-leaking as being something that
> it was necessary to preserve, because the only use case
> for it is something you can't do with an LC anyway.
> The reasons for the variable-leaking being preserved are
> (1) it fell out of the implementation and (2) it makes the
> documentation slightly simpler, since LCs can be described
> fully and accurately in terms of translation to for-loops.
> Whether those are *good* reasons or not is debatable.
It was the cheapest implementation; it was known at the time that it
wasn't ideal. I'd like to fix this in 3.0, so that LC's are just a
special case of GE's.
> In Py3k it's possible that this will be resolved by making
> for-loop variables local to the loop as well. Or maybe not.
Definitely not. There are lots of uses for the loop control variable
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev