Possible Duplicate:
Inspect python class attributes
I need to get a clean list of the names of all attributes defined my me in a class. Lets say I have the next class:
class MyClass(object):
attr1 = None
attr2 = 2
attr3 = "Hello world"
I would like to know if there is something that allows me to do:
>>> some_method(MyClass) # <- check class
['attr1', 'attr2', 'attr3']
>>> my_class = MyClass()
>>> some_method(my_class) # <- check instance of MyClass
['attr1', 'attr2', 'attr3']
I can't rely on the built-in method dir
since it also returns attributes like __class__
, __getattr__
and any method the class has. I mean, I need to get ONLY the attributes defined in the class, not the built-in ones too, neither the methods.
Is that even possible? or is there any way to know what attributes are built-in and which ones are defined by me so that I can loop over the list dir
returns and make some filter
ing?
Thanks in advance for any help!!