class father:
def __init__(self):
print("Dad")
class mother:
def __init__(self):
print("Mom")
class child(father,mother):
def __init__(self):
super().__init__()
print("Child")
child()
Output:
Dad
Child
How to do it correctly such that the mother is initialized as well?
I understand this problem has been addressed previously, but I can only find either long explanations about MRO or modifications to the father and mother class, which is in my case not allowed. I'm sure this problem is more trivial than that...
super().__init__calls to all__init__s?__init__s. That means infatherandmotheras well. Right now yoursupercall goes to thefather's__init__, printsDadand goes back tochild. You need to add anothersupercall there as well in order for it to go to themother's__init__as wellsuper()? That's the idiomatic way of calling the parent...super()isn't simply idiomatic, it the right way to do it, especially if multiple inheritance is involved.