I am trying to figure out what kind is an object in python (is a method? is a class? is a static method?) using attributes, for example:
Iterating over objects present in __dict__
attribute object of my module:
If an object has an attribute called __class__
and the __name__
atribute of it equals to "class"
then it is a class. If not, it is a variable defined in my module (of class whatever __name__
has returned).
If an object has an attribute called "func_name"
is a method.
The issue arises when I encounter so called properties. A property object prop.attr("__class__").attr("__name__")"
will return "property"
. But how could I extract the type of the property? I want to know if it is a float, an integer, etc.
>>>Vector3 is a class
>>>Vector3 has a member Y (property)
>>><property object at 0x000002840809E278>
>>>Y property attributes: ['__class__', '__delattr__', '__delete__', '__doc__', '__format__', '__get__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__set__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'deleter', 'fdel', 'fget', 'fset', 'getter', 'setter']
I am not able to use the getter
, __get__
, etc because I don't have an instance of an object to call this property over it (getter takes an object as argument).
For context, I am inspecting these objects from C++ code using Boost.Python, but as I am using just attributes I think it is not relevant for the solution. Just to justify why I am not using a more regular method, say with inspect module.