problem with str()

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Mar 15 19:31:53 EDT 2007


En Thu, 15 Mar 2007 17:32:24 -0300, <kyosohma at gmail.com> escribió:

> methodList = [str for str in names if callable(getattr(obj, str))]
>
> instead, do something like this:
>
> methodList = [i for i in names if callable(getattr(obj, i))]

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'>

-- 
Gabriel Genellina




More information about the Python-list mailing list