class Parent1(object):
def foo(self):
print "P1 foo"
def bar(self):
print "P1 bar"
class Parent2(object):
def foo(self):
print "P2 foo"
def bar(self):
print "P2 bar"
class Child(Parent1, Parent2):
def foo(self):
super(Parent1, self).foo()
def bar(self):
super(Parent2, self).bar()
c = Child()
c.foo()
c.bar()
The intention is to inherit foo() from Parent1 and bar() from Parent2. But c.foo() resulting for parent2 and c.bar() is reulting error. Please point to the problem and provide solution.
superis the class to start looking "above" in the inheritance hierarchy, sofoowill be fromParent2andbarwill be fromobject(which has no such attribute, presumably causing the error you mention only in passing). Instead, useChildandParent1in yoursupercalls.Parent1.foo()andParent2.bar()?__init__and other "magic" methods included, follow the same rules.