Why A is not called in this code: [is it because of mro : left to right then A class should be called?]
class A:
def __init__(self,name):
print('inside a',name)
class B:
def __init__(self,name):
print('inside b',name)
class C(B,A):
def __init__(self,name):
print('inside c',name)
super().__init__(name)
c = C('hello')
Output :
inside c hello
inside b hello
But when I defined it like this basically a parent class then it is working properly as expected.[Why A class is called here ]Code:
class D:
def __init__(self,name):
print('inside d',name)
class A(D):
def __init__(self,name):
print('inside a',name)
super().__init__(name)
class B(D):
def __init__(self,name):
print('inside b',name)
super().__init__(name)
class C(B,A):
def __init__(self,name):
print('inside c',name)
super().__init__(name)
c = C('hello')
output:
inside c hello
inside b hello
inside a hello
inside d hello
super()to work right with multiple inheritance, you have to use it in every class in the hierarchy - even the base classes.