list comprehensions put non-names into namespaces!

Mel Wilson mwilson-to at sympatico.ca
Fri May 26 13:04:34 CEST 2006


skip at pobox.com wrote:
>     Lonnie> List comprehensions appear to store their temporary result in a
>     Lonnie> variable named "_[1]" (or presumably "_[2]", "_[3]" etc for
>     Lonnie> nested comprehensions)
> 
> Known issue.  Fixed in generator comprehensions.  Dunno about plans to fix
> it in list comprehensions.  I believe at some point in the future they may
> just go away or become syntactic sugar for a gen comp wrapped in a list()
> call.

Point of information, would this be the interpreter putting
the result of its last calculation in _ ?

Python 2.4.2 (#1, Jan 23 2006, 21:24:54)
[GCC 3.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more 
information.
 >>> [2*x for x in range(5)]
[0, 2, 4, 6, 8]
 >>> _[4]
8



         Mel.



More information about the Python-list mailing list