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

Path csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '"""': 0.05; 'executed': 0.07; 'expressions': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'unexpected': 0.09; 'python': 0.10; 'explicitly': 0.15; 'example)': 0.16; 'expression.': 0.16; 'expressions,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'scope.': 0.16; 'subject:class': 0.16; 'url:whatsnew': 0.16; 'value;': 0.16; 'wrote:': 0.16; 'differ': 0.18; 'documented': 0.18; 'variable': 0.18; 'versions': 0.20; 'leave': 0.23; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'separate': 0.27; 'then.': 0.27; 'sentence': 0.29; "i'm": 0.30; 'probably': 0.31; 'url:python': 0.33; 'accessible': 0.33; 'list': 0.34; 'but': 0.36; 'url:org': 0.36; 'assigned': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'names': 0.38; 'wrong': 0.38; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'future': 0.60; 'making': 0.62; 'between': 0.65; 'url:4': 0.70; 'notably,': 0.84; 'otten': 0.84; 'respect.': 0.84; 'leak': 0.91; 'url:reference': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: Ensure unwanted names removed in class definition
Date Thu, 13 Aug 2015 07:44:39 +0200
Organization None
References <85fv3oj2y6.fsf@benfinney.id.au> <mqfpbu$1ev$1@ger.gmane.org> <85a8twi0j7.fsf@benfinney.id.au>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Gmane-NNTP-Posting-Host p57bd90ba.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.156.1439444692.3627.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1439444692 news.xs4all.nl 2966 [2001:888:2000:d::a6]:38024
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:95333

Show key headers only | 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