Python多重继承,从一个公共子类初始化

ted*_*123 3 python

如何使一个公共子类初始化它继承的所有父类?

class Mom(object):
    def __init__(self):
        print("Mom")

class Dad(object):
    def __init__(self):
        print("Dad")

class Child(Mom, Dad):
    def __init__(self):
        super(Child, self).__init__()

c = Child() #only prints Mom
Run Code Online (Sandbox Code Playgroud)

ᴀʀᴍ*_*ᴍᴀɴ 5

他们缺少合作子类化工作所需super()Mom和调用中的调用Dad.

class Mom(object):
    def __init__(self):
        super(Mom, self).__init__()
        print("Mom")

class Dad(object):
    def __init__(self):
        super(Dad, self).__init__()
        print("Dad")

class Child(Dad, Mom):
    def __init__(self):
        super(Child, self).__init__()
c = Child() # Mom, Dad
Run Code Online (Sandbox Code Playgroud)