Determine if given class attribute is a property or not, Python object
python
Solution
You need to look at the class (this is the case for descriptors in general), which for objects you can find via the `__class__` attribute or by using the type function:
>>> obj.__class__.my_property
<property object at 0xb74bd16c>
or by
>>> type(obj).my_property
<property object at 0xb720b93c>
These result in the same "property object" as if you were to directly check the attribute of the class (implying you know the class' name in your code instead of checking it dynamically like you probably should rather do):
>>> A.my_property
<property object at 0xb7312345>
So to test if a specific attribute of an object is a property, this would be one solution:
>>> isinstance(type(obj).my_property, property)
True
Problem
It's all in the title. Here is the following example: ``` class A(object): my_var = 5 def my_method(self, drink='beer'): return 'I like %s' % drink @property def my_property(self): return 'I do not drink coffee' ``` I instantiate an A object and I want to know the type of each attribute and if it is a callable. For this I'm using `dir()`. ``` obj = A() for attr in dir(obj): print 'Type: %s' % type(obj) print 'Is callable: %s' % callable(attr) ``` I have to know also if an attribute is a property. I'm sure that there is a way to know this. All suggestions will be appreciated.