I'm trying to understand how super works in python's multiple inheritance for the superclasses, for example in the code below:
class First():
def __init__(self, parm1, **kwargs):
super().__init__(**kwargs)
self.parm1 = parm1
self.parm3 = 'one'
class Second():
def __init__(self, parm2 = 'zero', **kwargs):
super().__init__(**kwargs)
self.parm2 = parm2
class Third(First,Second):
def __init__(self,parm1):
super().__init__(parm1=parm1)
trd = Third('tst')
print(trd.parm1) # 'tst'
print(trd.parm3) # 'one'
print(trd.parm2) # 'zero'
If I remove the super().__init__(**kwargs)
the execution ends with
'Third' object has no attribute 'parm2'
printing only the parm1
and parm3
, even if I declared the hierarchy in Class Third(First,Second)
.
I know all classes inherit from Object class, but I don't understand how it could be involved with the super() class in the parent classes and how the latter allows to access to the second parent's attributes.