I'm trying to get all the class level attributes on a python instance, but when I access the class dictionary (inst.__class__.__dict__
), I won't get the class level attributes from the parent type
ex:
class Parent:
var1 = ''
class Child(Parent):
var2 = ''
child_inst = Child()
for key in child_inst.__class__.__dict__:
print(key)
output: 'var2' (ignoring __atr__
attributes)
I can achieve what I want by doing a second loop through
for key in child_inst.__class__.__base__.__dict__:
print(key)
output: 'var1'
but for a complex inheritance hierarchy I'd need to do this an unknown number of times. is there a simpler way to do this?
Edit:
I need to get unresolved properties for what I'm attempting to do, not the attribute values themselves I tried using inspect.getmembers, however that appears to resolve the properties