class MyClass(Class1, Class2):
pass
Both parents have a getImage method.
thing = MyClass()
thing.getImage() #I want to call Class1's
thing.getImage() #I want to call Class2's
Which getImage gets called? How do I specify which one to call?
In this case,
thing.getImagewill callClass1.getImageprovided that it exists. If you want to call the other, you can use the longer form:These things can be inspected via the class’s method resolution order (
__mro__):This shows that
bazis searched for the method first, thenfoo, thenbarand finallyobject.Further reading about multiple inheritance
Further reading about mro