This question already has an answer here:
- python get only class attribute no superclasses 3 answers
Let's say I define class A:
>>> class A:
... a = 1
... class SubA:
... sub_a = { 'a': 1, 'b': 1}
Then I define class B that inherits from A:
>>> class B(A):
... pass
Now, check __dict__ of A and __dict__ of B:
>>> A.__dict__
{'a': 1, '__module__': '__builtin__', '__doc__': None, 'SubA': <class __builtin_ _.SubA at 0x02CAA3E8>}
>>> B.__dict__
{'__module__': '__builtin__', '__doc__': None}
Somehow, B.__dict__ contains neither 'a' nor 'SubA'. Now if we do:
>>> A.a
1
>>> B.a
1
>>> A.SubA
<class __builtin__.SubA at 0x02CAA3E8>
>>> B.SubA
<class __builtin__.SubA at 0x02CAA3E8>
First question: why B.__dict__ does not contain 'a' and 'SubA'? Second question: Why B.a and B.SubA give the expected results, although neither 'a' nor 'SubA' is in B's __dict__?
Thanks!