Created
November 28, 2016 14:48
-
-
Save stefanocrosta/1a58e020965b38227f3f77b2858fad4a to your computer and use it in GitHub Desktop.
full example of python multiple inheritance with MRO
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
# see http://stackoverflow.com/a/3277407/422670 and in particular comment by http://stackoverflow.com/users/81636/gatoatigrado | |
class First(object): | |
def __init__(self): | |
print "first prologue" | |
super(First, self).__init__() | |
print "first epilogue" | |
class Second(First): | |
def __init__(self): | |
print "second prologue" | |
super(Second, self).__init__() | |
print "second epilogue" | |
class Third(First): | |
def __init__(self): | |
print "third prologue" | |
super(Third, self).__init__() | |
print "third epilogue" | |
class Fourth(Second, Third): | |
def __init__(self): | |
print "MRO: ", self.__class__.__mro__ | |
print "Fourth __init__" | |
super(Fourth, self).__init__() | |
print "that's it" | |
Fourth() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected output: