Skip to content

Instantly share code, notes, and snippets.

@steelywing
Created March 19, 2014 07:18
Show Gist options
  • Save steelywing/9636906 to your computer and use it in GitHub Desktop.
Save steelywing/9636906 to your computer and use it in GitHub Desktop.
python multiple inheritance
class Base(object):
def __init__(self, c):
print('Base called by {0}'.format(c))
super().__init__()
class ParentA(Base):
def __init__(self, c):
print('ParentA called by {0}'.format(c))
#Base.__init__(self, 'ParentA')
super().__init__('ParentA')
class ParentB(Base):
def __init__(self, c):
print('ParentB called by {0}'.format(c))
super().__init__('ParentB')
class Child(ParentA, ParentB):
def __init__(self, c):
print('Child called by {0}'.format(c))
super().__init__('Child')
Child('Construct')
print(Child.mro())
'''
Output
-------------------------------
Child called by Construct
ParentA called by Child
ParentB called by ParentA
Base called by ParentB
[<class '__main__.Child'>, <class '__main__.ParentA'>, <class '__main__.ParentB'>, <class '__main__.Base'>, <class 'object'>]
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment