问题描述
为什么在此代码中未调用A:[是因为mro:从左到右然后应调用A类?]
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')
输出:
inside c hello
inside b hello
但是当我这样定义它基本上是一个父类时,它就可以按预期正常工作。[为什么在这里调用一个类]代码:
class D:
def __init__(self,name):
print('inside d',name)
class A(D):
def __init__(self,name)
super().__init__(name)
class B(D):
def __init__(self,name)
super().__init__(name)
class C(B,A):
def __init__(self,name)
super().__init__(name)
c = C('hello')
输出:
inside c hello
inside b hello
inside a hello
inside d hello
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)