Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #95333

Re: Ensure unwanted names removed in class definition

From Peter Otten <__peter__@web.de>
Subject Re: Ensure unwanted names removed in class definition
Date 2015-08-13 07:44 +0200
Organization None
References <85fv3oj2y6.fsf@benfinney.id.au> <mqfpbu$1ev$1@ger.gmane.org> <85a8twi0j7.fsf@benfinney.id.au>
Newsgroups comp.lang.python
Message-ID <mailman.156.1439444692.3627.python-list@python.org> (permalink)

Show all headers | View raw


Ben Finney wrote:

> Peter Otten <__peter__@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.
"""

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Ensure unwanted names removed in class definition Peter Otten <__peter__@web.de> - 2015-08-13 07:44 +0200

csiph-web