robcarlton wrote:
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
The full story is actually more subtle. The name 'obj'
*is* accessible from a nested scope if you do some
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
Peter Otten wrote:
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.
x.question = "Are you sure?"
I should clarify. It works fine for me when I've already globally
assigned obj to something else. D'oh!
--
Mic
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.
>
robcarlton wrote:
> 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 is
How about using the vars builtin?
Michael Hoffman schrieb:
robcarlton wrote:
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)
That works
robcarlton wrote:
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)
That works fine for me with Python 2.4.
This is the best way to do it:
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