To get all property of a class?

Mike C. Fletcher mcfletch at
Mon Jun 30 19:13:58 CEST 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'.


  Mike C. Fletcher
  Designer, VR Plumber, Coder

More information about the Python-list mailing list