我有3个A,B和D类,如下所示
class A(object):
def test(self):
print "called A"
class B(object):
def test(self):
print "called B"
class D(A,B):
def test(self):
super(A,self).test()
inst_d=D()
inst_d.test()
----------------------------------------
Output:
called B
Run Code Online (Sandbox Code Playgroud)
问题:在D.test(),我在打电话super(A,self).test().B.test()即使该方法A.test()也存在,为什么只被调用?
因为你告诉它不要.在D.test你告诉它调用A 的父母的测试方法- 那是什么super.
通常,您希望在super调用中使用当前的类名.