Multiple Inheritance

Date: February 22nd 2016
Last updated: February 9th 2017

This is a quick reminder of what to do using a common example.

class A:
    def meth(self):
        print("meth of A called")

class B(A):
    def meth(self):
        print("meth of B called")
        super().meth()

class C(A):
    def meth(self):
        print("meth of C called")
        super().meth()

class D(B,C):
    def meth(self):
        print("meth of D called")
        super().meth()

Output

from myModule import D
x = D()
x.meth()
#meth of D called
#meth of B called
#meth of C called
#meth of A called

# The key point here is that the base class only gets called once, not twice.

Useful resources

results matching ""

    No results matching ""