Tuesday, 28 October 2014

MRO in Python

In Python, calling the super class' __init__ is optional.
However, if you override the __init__ of a class, you must explicitly call the parent class' __init__ with the current parameters.

This is done by :

super( nameofclass, self ).__init__() 



Python however supports Multiple Inheritance ,i.e a class can have more than one super class.

The MRO(Method Resolution Order - the order in which base classes are searched when looking for a method) is as follows .


1)Depth First Left to Right.
2)If any class is repeated in this search, all but the last occurrence of the class will be deleted.
3)Reject any class that has an inconsistent ordering of base classes.

No comments:

Post a Comment