Skip to content

Instantly share code, notes, and snippets.

@betrcode
Created February 26, 2014 13:20
Show Gist options
  • Save betrcode/9229347 to your computer and use it in GitHub Desktop.
Save betrcode/9229347 to your computer and use it in GitHub Desktop.
Python inheritance __init__ calling
class BaseWithInit(object):
def __init__(self):
print "Init BaseWithInit"
class ClassWithoutInit(BaseWithInit):
pass
class ClassWithInit(BaseWithInit):
def __init__(self):
print "Init ClassWithInit"
class ClassWithInitCallingSuper(BaseWithInit):
def __init__(self):
print "Init ClassWithInitCallingSuper"
super(ClassWithInitCallingSuper, self).__init__()
if __name__ == '__main__':
print "----------------------"
print "ClassWithoutInit"
ClassWithoutInit()
print "----------------------"
print "ClassWithInit"
ClassWithInit()
print "----------------------"
print "ClassWithInitCallingSuper"
ClassWithInitCallingSuper()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment