Ben Finney wrote:

> Peter Otten <__pete...@web.de> writes:
> 
>> I would probably use a generator expression. These don't leak names:
> 
> That's an unexpected inconsistency between list comprehensions versus
> generator expressions, then. Is that documented explicitly in the Python
> 2 documentation?

https://docs.python.org/2/reference/expressions.html

has one sentence

"""
Note that the comprehension is executed in a separate scope, so names 
assigned to in the target list don’t “leak” in the enclosing scope.
"""

-- which is wrong unless I'm misunderstanding something, but

https://docs.python.org/2.4/whatsnew/node4.html

clearly states

"""
Generator expressions differ from list comprehensions in various small ways. 
Most notably, the loop variable (obj in the above example) is not accessible 
outside of the generator expression. List comprehensions leave the variable 
assigned to its last value; future versions of Python will change this, 
making list comprehensions match generator expressions in this respect.
"""


-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to