eval function not working how i want it dag namn

2005-04-15 Thread robcarlton
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

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: eval function not working how i want it dag namn

2005-04-15 Thread robcarlton
thanks. I'll use the getattr function now, and I think I understand
where I went wrong with eval. I was thinking in Lisp where the lexical
scope would mean that obj is defined

-- 
http://mail.python.org/mailman/listinfo/python-list