Skip to content

Instantly share code, notes, and snippets.

@troyunverdruss
Last active June 19, 2018 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troyunverdruss/ee871292183e9dfea13e10790b639453 to your computer and use it in GitHub Desktop.
Save troyunverdruss/ee871292183e9dfea13e10790b639453 to your computer and use it in GitHub Desktop.
Multiple inheritance with Python 3
#!/usr/bin/env python3
class A(object):
def go(self):
print("Entering A")
print("go A go")
class B(A):
def go(self):
print("Entering B")
super().go()
print("go B go")
class C(A):
def go(self):
print("Entering C")
super().go()
print("go C go")
class D(B, C):
def go(self):
print("Entering D")
super().go()
print("go D go")
d = D()
print("Method Resolution Order for D: {}".format(D.__mro__))
print("Calling d.go()")
d.go()
# Sample output
# Method Resolution Order for D: (<class '__main__.D'>, <class '__main__.B'>, <class '__main__.C'>, <class '__main__.A'>, <class 'object'>)
# Calling d.go()
# Entering D
# Entering B
# Entering C
# Entering A
# go A go
# go C go
# go B go
# go D go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment