The __dict__
method does not produce the same result when the inherited classes are initialized directly instead of using the using super().__init__()
. Why?:
class A:
def __init__(self):
self.att_a = "A"
class B:
def __init__(self):
self.att_b = "B"
class C(A, B):
def __init__(self):
A.__init__(self)
B.__init__(self)
self.att_c = "C"
def get_att(self):
print(self.__dict__)
c = C()
c.get_att()
Result: {'attA': 'A', 'attB': 'B', 'attC': 'C'}
Why using super().__init__()
does not yield the same result:
class A:
def __init__(self):
self.att_a = "A"
class B:
def __init__(self):
self.att_b = "B"
class C(A, B):
def __init__(self):
super().__init__() # Modification
self.att_c = "C"
def get_att(self):
print(self.__dict__)
c = C()
c.get_att()
Result: {'att_a': 'A', 'att_c': 'C'}