Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95287
| References | <85fv3oj2y6.fsf@benfinney.id.au> <mqfpbu$1ev$1@ger.gmane.org> |
|---|---|
| Date | 2015-08-13 01:59 +1000 |
| Subject | Re: Ensure unwanted names removed in class definition |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.114.1439395153.3627.python-list@python.org> (permalink) |
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
Re: Ensure unwanted names removed in class definition Chris Angelico <rosuav@gmail.com> - 2015-08-13 01:59 +1000
csiph-web