multiple-inheritance

python multiple inheritance from different paths with same method name

python multiple inheritance from different paths with same method name Question: With the following code sample, can super be used, or C has to call A.foo and B.foo explicitly? class A(object): def foo(self): print ‘A.foo()’ class B(object): def foo(self): print ‘B.foo()’ class C(A, B): def foo(self): print ‘C.foo()’ A.foo(self) B.foo(self) Asked By: sayap || Source …

Total answers: 9

How does Python's super() work with multiple inheritance?

How does Python's super() work with multiple inheritance? Question: How does super() work with multiple inheritance? For example, given: class First(object): def __init__(self): print "first" class Second(object): def __init__(self): print "second" class Third(First, Second): def __init__(self): super(Third, self).__init__() print "that’s it" Which parent method of Third does super().__init__ refer to? Can I choose which runs? …

Total answers: 18

Abstract class + mixin + multiple inheritance in python

Abstract class + mixin + multiple inheritance in python Question: So, I think the code probably explains what I’m trying to do better than I can in words, so here goes: import abc class foo(object): __metaclass__ = abc.ABCMeta @abc.abstractmethod def bar(self): pass class bar_for_foo_mixin(object): def bar(self): print “This should satisfy the abstract method requirement” class …

Total answers: 2

How does Python's "super" do the right thing?

How does Python's "super" do the right thing? Question: I’m running Python 2.5, so this question may not apply to Python 3. When you make a diamond class hierarchy using multiple inheritance and create an object of the derived-most class, Python does the Right Thing (TM). It calls the constructor for the derived-most class, then …

Total answers: 5

What is a mixin and why is it useful?

What is a mixin and why is it useful? Question: In Programming Python, Mark Lutz mentions the term mixin. I am from a C/C++/C# background and I have not heard the term before. What is a mixin? Reading between the lines of this example (which I have linked to because it is quite long), I …

Total answers: 18

What does 'super' do in Python? – difference between super().__init__() and explicit superclass __init__()

What does 'super' do in Python? – difference between super().__init__() and explicit superclass __init__() Question: What’s the difference between: class Child(SomeBaseClass): def __init__(self): super(Child, self).__init__() and: class Child(SomeBaseClass): def __init__(self): SomeBaseClass.__init__(self) I’ve seen super being used quite a lot in classes with only single inheritance. I can see why you’d use it in multiple inheritance …

Total answers: 11