How we can extend multiple Python classes in inheritance?

PythonServer Side ProgrammingProgramming

As per Python documentation ‘super’ can help in extending multiple python classes in inheritance.  It returns a proxy object that delegates method calls to a parent or sibling class of type. This is useful for accessing inherited methods that have been overridden in a class. The search order is same as that used by  getattr() except that the type itself is skipped.

In other words, a call to super returns a fake object which delegates attribute lookups to classes above you in the inheritance chain. Points to note:

This does not work with old-style classes.You need to pass your own class and instance to super in Python 2.x. This requirement was waived in 3.x.

This will handle all multiple inheritance correctly. A method resolution order is generated and the lookups go through parent classes in this order.

raja
Published on 29-Jan-2018 12:24:55
Advertisements