eval function not working how i want it dag namn

robcarlton robbiefcarlton at hotmail.com
Fri Apr 15 08:14:21 EDT 2005


hi everybody
I've written this function to make a list of all of an objects
attributes and methods (not for any reason, I'm just learning)

def list_members(obj)
    l = dir(obj)
    return map(lambda x : eval('obj.'+x), l)

but I get an error saying that obj isn't defined. As I understand it
eval has access to the current local namespace, which does contain
object, so I'm not sure whats going wrong.

ps Im sure there are better ways of doing the above which doesn't call
the eval function, and while I'd be glad to know what it is, I'd still
like to understand why my way isnt working

thanks




More information about the Python-list mailing list