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


Groups > comp.lang.python > #95287

Re: Ensure unwanted names removed in class definition

Path csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed8.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.031
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'cc:addr:python-list': 0.09; 'python': 0.10; '(but': 0.15; 'thu,': 0.15; 'cleaner': 0.16; 'expression.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'lambda': 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; 'explicit': 0.22; 'am,': 0.23; 'header:In-Reply- To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; '13,': 0.29; 'probably': 0.31; 'class': 0.33; 'list': 0.34; 'received:google.com': 0.35; 'comment': 0.35; 'but': 0.36; 'subject:: ': 0.37; 'why': 0.39; 'rather': 0.39; 'per': 0.62; 'more': 0.63; 'chrisa': 0.84; 'otten': 0.84; 'to:none': 0.91; 'leak': 0.91; 'favour': 0.93
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; bh=7RwBRYxy2OjLCuLeODTHkXccDgSnI2GgIvwb7U4jgPc=; b=vPHNZ3VpAev2+ujGGERG70g31TCWpJDQgM+j0L9UKVTJMs8WwiPY2gdUndzA6W9Sjd kNDxciyaNTPHPZkdqPwvi/cZqMoCzKnL2nB2w2NRGnfaC3485jeNImRoWDYz8z5TsoM7 RVBNDSgXoDZs7AOHyFPXQZhoDDCNbnZC76oqyHWsb2olvwXl/pv2UP8LhJ/3X3IpLD1v C/0SaZ9B4+rYEQgxxgDbJkmi8R7tsKVnFCOxpItEa2/4yKRk1YP+rdnHszo7S3zjcqVB rud8i5WuPVkn/8tAgTouocaq6DskiMf37YbVoODHDQ3kkq7a8dlmQO6Kqa+qKyB8MmJN JG9w==
MIME-Version 1.0
X-Received by 10.107.12.166 with SMTP id 38mr21608200iom.157.1439395150900; Wed, 12 Aug 2015 08:59:10 -0700 (PDT)
In-Reply-To <mqfpbu$1ev$1@ger.gmane.org>
References <85fv3oj2y6.fsf@benfinney.id.au> <mqfpbu$1ev$1@ger.gmane.org>
Date Thu, 13 Aug 2015 01:59:10 +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
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.114.1439395153.3627.python-list@python.org> (permalink)
Lines 17
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1439395153 news.xs4all.nl 2849 [2001:888:2000:d::a6]:35562
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:95287

Show key headers only | View raw


On Thu, Aug 13, 2015 at 1:39 AM, Peter Otten <__peter__@web.de> wrote:
> But I would probably use a generator expression. These don't leak names:
>
> Python 2.7.6 (default, Jun 22 2015, 17:58:13)
> [GCC 4.8.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> class Parrot:
> ...     a = [per for per in "abc"]
> ...     b = list(trans for trans in "def")
> ...

Ooh neat trick! Much cleaner than the explicit lambda that I
suggested. Withdrawing my recommendation in favour of this (but with
an explanatory comment explaining why list(genexp) is used rather than
a list comp).

ChrisA

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


Thread

Re: Ensure unwanted names removed in class definition Chris Angelico <rosuav@gmail.com> - 2015-08-13 01:59 +1000

csiph-web