'super'如何在Python中使用多继承?

时间:2017-08-18 15:55:51

标签: python python-2.7 multiple-inheritance super

我有以下代码:

class TestA(object):
    def __init__(self, *args):
        super(TestA, self).__init__()
        print 'TestA'

class TestB(object):
    def __init__(self, my_var=None):
        super(TestB, self).__init__()
        print 'TestB', my_var

class TestC(object):
    def __init__(self, my_var=None):
        super(TestC, self).__init__()
        print 'TestC', my_var

class TestD(TestB, TestA, TestC):
    def __init__(self):
        print 'TestD'
        super(TestD, self).__init__("Hello World")

输出

TestD
TestC None
TestA
TestB Hello World

我希望有:

TestD
TestB Hello World
TestA
TestC Hello World

看起来超级只获得第一个父级。 当我读到一个answer in stackoverflow时,我认为它会按照我的预期行事。 我的代码或理解有什么问题?

提前谢谢。

0 个答案:

没有答案