Created
February 26, 2014 13:20
-
-
Save betrcode/9229347 to your computer and use it in GitHub Desktop.
Python inheritance __init__ calling
This file contains hidden or 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
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