Created
March 19, 2014 07:18
-
-
Save steelywing/9636906 to your computer and use it in GitHub Desktop.
python multiple inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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