I would like to retrieve all the attributes of a given instance. I know I could use __dict__
, but it's not working in my case, because I'm declaring some attributes using the @property
decorator.
class A():
def __init__(self):
self.a = ""
self._b = ""
@property
def b(self):
return self._b
@b.setter
def b(self, value):
self._b = value
def f(self):
print "hello"
These are the results I get:
>>> A().__dict__
{'a': '', '_b': ''}
>>> dir(A())
['__doc__', '__init__', '__module__', '_b', 'a', 'b', 'f']
But the result I want is the following one:
>>> get_all_the_attributes(A())
{'a': '', '_b': '', 'b': ''}
Or:
>>> get_all_the_attributes(A())
['a', '_b', 'b']
Is there any way to do that ?