Let say I have 3 classes: A, B and C. A is a base class for B and B is for C. Hierarchy is kept normally here, but for one method it should be different. For C class it should act like it was inherited from A.
For example like this:
class A(object):
def m(self):
print 'a'
class B(A):
def m(self):
super(B, self).m()
print 'b'
class C(B):
def m(self):
super(A, self).m()
print 'c'
So basically it should work like this:
a = A()
a.m()
a
b = B()
b.m()
a
b
c = C()
c.m()
a
c
But it is not going to work for C class, because I get this error:
AttributeError: 'super' object has no attribute 'm'
To solve this for C class I could inherit from class A, but I want to inherit everything from B and for that specific method m call super for base class A. I mean that method is one exception. Or should I call it somehow differently for class C in order to work?
How can I do that?
A.m(self)instead of usingsuper?selfparameter manualysuper().super(SomeClass, someobject)will lookup attributes in the class that followsSomeClassin the MRO ofsomeobject. In your casesuper(A, self).m()refers toobject.m(self), which clearly does not exist.