eval function not working how i want it dag namn
Peter Otten
__peter__ at web.de
Fri Apr 15 11:35:38 EDT 2005
Michael Hoffman wrote:
>> def list_members(obj)
>>l = dir(obj)
>>return map(lambda x : eval('obj.'+x), l)
>
> That works fine for me with Python 2.4.
Python 2.4 (#6, Jan 30 2005, 11:14:08)
[GCC 3.3.3 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def lm(obj):
... l = dir(obj)
... return map(lambda x: eval("obj." + x), l)
...
>>> class X:
... pass
...
>>> x = X()
>>> x.question = "Are you sure?"
>>> lm(x)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 3, in lm
File "<stdin>", line 3, in <lambda>
File "<string>", line 0, in ?
NameError: name 'obj' is not defined
>>>
Peter
More information about the Python-list
mailing list