problem with str()

7stud bbxx789_05ss at yahoo.com
Fri Mar 16 04:25:21 CET 2007


On Mar 15, 5:31 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> The fact that a list comprehension "leaks" its variables into the  
> containing scope is a bit weird.
> A generator expression doesn't:
>
> py> str
> <type 'str'>
> py> w = (str for str in range(10))
> py> w
> <generator object at 0x00AD7C38>
> py> str
> <type 'str'>
> py> w.next()
> 0
> py> str
> <type 'str'>

On Mar 15, 5:34 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> or:
>
>    methodList = list(str for str in names if callable(getattr(obj, str)))
>
> genexps, unlike listcomps, make a new scope for their index variable.


Thanks.




More information about the Python-list mailing list