を呼び出します。私はこののpython多重継承、私はPythonで多重継承で何かをしようとしていた基底クラスの関数
class ParentOne:
def foo(self):
print("ParentOne foo is called")
class ParentTwo:
def foo(self):
print("ParentTwo foo is called")
class Child(ParentOne, ParentTwo):
# how is this working
def call_parent_two_foo(self):
super(ParentOne, self).foo()
# This does not work
def call_parent_foo(self):
super(ParentTwo, self).foo()
def call_super_foo(self):
super(Child, self).foo()
def foo(self):
print("Child foo is called")
if __name__ == "__main__":
child = Child()
child.foo()
child.call_super_foo()
child.call_parent_two_foo()
# child.call_parent_foo() #This gives the below error
# super(ParentTwo, self).foo()
# AttributeError: 'super' object has no attribute 'foo'
を思い付く、それは私がsuper(ParentOne, self).foo()
の呼び出しは、このケースで評価され、どのようにと混乱しています次の出力
Child foo is called
ParentOne foo is called
ParentTwo foo is called
を与えます。私の理解あたりとしてParentOne
クラスはParentTwo
クラスのメソッドと属性の任意のアイデアを持っていません。多重継承の場合には、スーパー作品をどのよう
はMRO –
@AnuragSharma取得/見るために彼らの方法です。 IIRCでは、魔法の '__mro__'属性でアクセスすることもできます。 – mgilson