Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95276
| Path | csiph.com!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.008 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; '"""': 0.05; '*not*': 0.07; 'cc:addr:python-list': 0.09; 'foo,': 0.09; 'incidental': 0.09; '\xe2\x80\x94': 0.09; 'python': 0.10; 'wed,': 0.15; 'explicitly': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'lambda': 0.16; 'py3': 0.16; 'subject:class': 0.16; 'wrote:': 0.16; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'aug': 0.20; 'work,': 0.21; 'function:': 0.22; 'code,': 0.23; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'does,': 0.29; 'code': 0.30; 'run': 0.33; 'class': 0.33; 'wrap': 0.33; 'correctly': 0.34; 'definition': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'but': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; '12,': 0.37; 'names': 0.38; 'protection': 0.60; 'beautiful': 0.66; 'worth': 0.67; 'apart': 0.70; 'skip:\xe2 10': 0.70; "'foo'": 0.84; 'bar)': 0.84; 'chrisa': 0.84; 'hardly': 0.84; 'to:none': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=rkpxoUVjwtFDAv3pyGKv6Bkn5k5TE7OY7zDPYdlWhOU=; b=jqZ+2sZW+iqtA+DbIksMEEQLDTQoi7y6ADX1QOzyascTQNetfDX/09dKHxmVryz+bC nQat7VutHrhPnlqrkzU1VCAonlVSLQNid8uHUO9bg4ck2AZuVJs6ac1BjaGTSjCocQ2+ VnaLgqjEV5JIGvjSi2UpKt3y7Rh03/Mc0Sd7EErLtneuOEBUdHTufctC79Pw+jsIcCoh Gqg2HziIsctChjIbhDtTP9SQepYPWKVHap+aSYjqeKLaAdmiXF2gcOeAYy7vaxDBLgnY i5zHfboy2rdI5I9if/LBpTHDPfdjyPJBzLQUJnBpHn5TTgwli88pVDOve0if7rkQ2UtN EXaA== |
| MIME-Version | 1.0 |
| X-Received | by 10.107.31.134 with SMTP id f128mr30200545iof.19.1439370870205; Wed, 12 Aug 2015 02:14:30 -0700 (PDT) |
| In-Reply-To | <85fv3oj2y6.fsf@benfinney.id.au> |
| References | <85fv3oj2y6.fsf@benfinney.id.au> |
| Date | Wed, 12 Aug 2015 19:14:30 +1000 |
| Subject | Re: Ensure unwanted names removed in class definition |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| 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.103.1439370878.3627.python-list@python.org> (permalink) |
| Lines | 28 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1439370878 news.xs4all.nl 2927 [2001:888:2000:d::a6]:32819 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:95276 |
Show key headers only | View raw
On Wed, Aug 12, 2015 at 7:01 PM, Ben Finney <ben+python@benfinney.id.au> wrote:
> class Parrot:
> """ A parrot with beautiful plumage. """
>
> plumage = [
> (foo, bar) for (foo, bar) in feathers.items()
> if bar == "beautiful"]
> del foo, bar # ← FAILS, “NameError: name 'foo' is not defined”
>
> How can I write the class definition with the list comprehension and
> *not* keep the incidental names — in code that will run correctly on
> both Python 2 and Python 3?
You could always do explicitly what a Py3 comprehension does, and wrap
it in a function:
plumage = (lambda: [
(foo, bar) for (foo, bar) in feathers.items()
if bar == "beautiful"])()
Hardly clean code, but it will work, and apart from having a redundant
layer of protection in Py3, will do exactly the same thing on both. Is
the lambda nesting cruft worth it?
ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Ensure unwanted names removed in class definition Chris Angelico <rosuav@gmail.com> - 2015-08-12 19:14 +1000
csiph-web