Skip to content

Instantly share code, notes, and snippets.

@mtigas
Created June 1, 2011 23:22
Show Gist options
  • Save mtigas/1003588 to your computer and use it in GitHub Desktop.
Save mtigas/1003588 to your computer and use it in GitHub Desktop.
class A(object):
def __init__(self):
print "A init"
class B(A):
def __init__(self):
print "B init"
super(B, self).__init__()
class C(B):
def __init__(self):
print "C init"
super(C, self).__init__()
# If you only want to super the A.__init__() and skip B
class D(B):
def __init__(self):
print "D init"
grandparent = super(B, self) # start the super call from B, not D, to resolve B's parent instead of D's
grandparent.__init__()
>>> a=A()
A init
>>> b=B()
B init
A init
>>> c=C()
C init
B init
A init
>>> d=D()
D init
A init
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment