loop scope

Josiah Carlson jcarlson at nospam.uci.edu
Mon Mar 15 14:53:35 EST 2004


>    t = f(a/c)
>    ... # and then later,
>    sl = [t * t for t in range(3)]
> 
> In this case, I would argue that it's an error for t to escape
> the expression scope _because_ it's used outside that scope -
> actually I think that was where we came in.  My personal view
> is that a list comprehension should have its own internal scope,
> period, but is that what `intuition' would lead most Python
> programmers to expect?  I don't know.

 From what I understand, the above case is taken care of in Python 2.4

In the case of:

t = f(a/c)
... # and then later,
s1 = []
for t in range(3):
     s1.append(t * t)

The behavior is unchanged in 2.4, t gets rebound.

  - Josiah



More information about the Python-list mailing list