Skip to main content

Posts

Showing posts with the label __init__

Python super() method and class inheritance

There is one more useful method in python. super()     It helps to handle inheritance of ancestor class. This sounds a bit of messy. So I'll try to explain. You have class A that does some useful things. And you have to use this class A everywhere in your application with adding some piece of functionality. You may inherit this class B(A) and expand it's functionality. Now you can use class B in stead of class A everywhere and get rid of redundant operations. # Main class (parent) class A ( object ) : def __init__ ( self ) : print ( u'class A constructor' ) # Main class ancestor (inheriting main class) class B ( A ) : def __init__ ( self ) : print ( u'class B constructor' ) super ( B , self ) . __init__ ( )     For live example:     NOTE! Code is theoretical for you because it is taken from live project. I'm using many own written methods here. Neither document  not it's methods are not dja...