Richard Thomas schrieb:
> I like that loop variables end up still in scope, as demonstrated so
> far on this list it is quite useful, but only when there is a break
> somewhere. The one that confuses me, therefore, is the dummy variables
> in a generator expression leaking into the scope defining that
> expression. Hence:
> 
> x = 0
> L = [f(x) for x in range(2)]
> assert x == 1
> 
> This is not particularly intuitive as the for loop in a generator
> expression can never break; generator expressions feel more "closed".

It's fixed in Python 3:

Python 3.0a4+ (py3k:62372, Apr 18 2008, 17:45:09)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> x = 0
 >>> l = [str(x) for x in range(2)]
 >>> x
0


Robin
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to