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


Groups > comp.lang.python > #95323 > unrolled thread

Re: Ensure unwanted names removed in class definition

Started byBen Finney <ben+python@benfinney.id.au>
First post2015-08-13 08:50 +1000
Last post2015-08-13 08:50 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Ensure unwanted names removed in class definition Ben Finney <ben+python@benfinney.id.au> - 2015-08-13 08:50 +1000

#95323 — Re: Ensure unwanted names removed in class definition

FromBen Finney <ben+python@benfinney.id.au>
Date2015-08-13 08:50 +1000
SubjectRe: Ensure unwanted names removed in class definition
Message-ID<mailman.146.1439419869.3627.python-list@python.org>
Peter Otten <__peter__@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 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")
> ... 
> >>> Parrot.per
> 'c'
> >>> Parrot.trans
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> AttributeError: class Parrot has no attribute 'trans'

We have a winner! That's elegant, expressive, and has the right
behaviour on both Python 2 and Python 3.

-- 
 \         “I turned to speak to God/About the world's despair; But to |
  `\   make bad matters worse/I found God wasn't there.” —Robert Frost |
_o__)                                                                  |
Ben Finney

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web