问题
I have 3 classes A,B,C , C inherting form A and B:
class A:
a = "ala"
class B:
b = "bla"
class C(A,B):
c = "cla"
How can I get only the Attributes of C, attributes that are not inherited ?
回答1:
You could access the __dict__
of C
directly via the vars
builtin.
>>> vars(C)['c']
'cla'
>>> vars(C)['b']
...
KeyError: 'b'
There's not much more to say without further context about what your real problem is.
来源:https://stackoverflow.com/questions/52127112/get-a-class-instance-only-declared-attributesnot-inherited