Re: Ensure unwanted names removed in class definition

2015-08-14 Thread Peter Otten
Ben Finney wrote: Peter Otten __pete...@web.de writes: Ben Finney wrote: Peter Otten __pete...@web.de writes: That's an unexpected inconsistency between list comprehensions versus generator expressions, then. Is that documented explicitly in the Python 2 documentation?

Re: Ensure unwanted names removed in class definition

2015-08-13 Thread Ben Finney
Peter Otten __pete...@web.de writes: Ben Finney wrote: Peter Otten __pete...@web.de writes: That's an unexpected inconsistency between list comprehensions versus generator expressions, then. Is that documented explicitly in the Python 2 documentation?

Re: Ensure unwanted names removed in class definition

2015-08-12 Thread MRAB
On 2015-08-12 10:01, Ben Finney wrote: How can I ensure incidental names don't end up in the class definition, with code that works on both Python 2 and Python 3? With the following class definition, the incidental names `foo` and `bar`, only needed for the list comprehension, remain in the

Re: Ensure unwanted names removed in class definition

2015-08-12 Thread Peter Otten
Ben Finney wrote: How can I ensure incidental names don't end up in the class definition, with code that works on both Python 2 and Python 3? With the following class definition, the incidental names `foo` and `bar`, only needed for the list comprehension, remain in the `Parrot`

Re: Ensure unwanted names removed in class definition

2015-08-12 Thread Ben Finney
MRAB pyt...@mrabarnett.plus.com writes: Have you thought about catching the NameError? I had not, but that is obvious now you say it. Thanks. Where there isn't a more elegant solution, I'll use that. It might not be elegant, but it's at least clear and expressive of the intent. Jussi

Re: Ensure unwanted names removed in class definition

2015-08-12 Thread Ben Finney
Peter Otten __pete...@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? Python 2.7.6 (default, Jun

Re: Ensure unwanted names removed in class definition

2015-08-12 Thread Peter Otten
Ben Finney wrote: Peter Otten __pete...@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?

Ensure unwanted names removed in class definition

2015-08-12 Thread Ben Finney
How can I ensure incidental names don't end up in the class definition, with code that works on both Python 2 and Python 3? With the following class definition, the incidental names `foo` and `bar`, only needed for the list comprehension, remain in the `Parrot` namespace:: __metaclass__ =

Re: Ensure unwanted names removed in class definition

2015-08-12 Thread Chris Angelico
On Wed, Aug 12, 2015 at 7:01 PM, Ben Finney ben+pyt...@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,

Re: Ensure unwanted names removed in class definition

2015-08-12 Thread Chris Angelico
On Thu, Aug 13, 2015 at 1:39 AM, Peter Otten __pete...@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: ...

Re: Ensure unwanted names removed in class definition

2015-08-12 Thread Jussi Piitulainen
Ben Finney writes: How can I ensure incidental names don't end up in the class definition, with code that works on both Python 2 and Python 3? With the following class definition, the incidental names `foo` and `bar`, only needed for the list comprehension, remain in the `Parrot`