To get all property of a class?
Mike C. Fletcher
mcfletch at rogers.com
Mon Jun 30 13:13:58 EDT 2003
manuel wrote:
>>import os
>>for (name,value) in os.__dict__:
>>print name,"=",value
>>
This should have been:
>>> import os
>>> for key,value in os.__dict__.items():
... print key,repr(value)
...
...
>The method of Egor don't work too. I've tried
>with a list of lamp objects (instances of povlamp class):
>
>for lamp in lamps:
> for i in dir(lamp):
> if i[0] != "_":
> print lamp.i
>
That last line should be:
print getattr(lamp, i )
that is, you want to use the string value stored in i to get the
attribute, not get an attribute named 'i'.
HTH,
Mike
_______________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/
More information about the Python-list
mailing list