Ensure unwanted names removed in class definition
Chris Angelico
rosuav at gmail.com
Wed Aug 12 11:59:10 EDT 2015
On Thu, Aug 13, 2015 at 1:39 AM, Peter Otten <__peter__ at 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
More information about the Python-list
mailing list