Skip to content

Instantly share code, notes, and snippets.

@olivierverdier
Created April 13, 2011 18:07
Show Gist options
  • Save olivierverdier/918044 to your computer and use it in GitHub Desktop.
Save olivierverdier/918044 to your computer and use it in GitHub Desktop.
super(explicitclass,self) vs super(self.__class__,self)
class A(object):
def msg(self):
print 'A',
class B(A):
def msg(self):
super(B,self).msg()
print 'B',
class C(B):
def msg(self):
super(C,self).msg()
print 'C',
bar = C()
bar.msg() # prints A B C
class A(object):
def msg(self):
print 'A',
class B(A):
def msg(self):
print super(self.__class__,self).msg()
print 'B',
class C(B):
def msg(self):
print super(self.__class__,self).msg()
print 'C',
foo = C()
foo.msg() # infinite recursion!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment