1

Can I perform multiple inheritance(python 3) using the super keyword if my child class inherits more than 1 class? Using Parentobject.__init__(self,*args,**kwargs) makes multiple inheritance easy But how to perform the same using super()

    class A:
       def __init__(self,a):
          self.a=a
    class C:
       def __init__(self,b):
          self.b=b
    
    class D(C,A):
       def __init__(self,a,b):
          A.__init__(self,a)
          C.__init__(self,b)
    
  • 1
    You can't do this with arbitrary super classes. The super classes need to be designed for this kind of inheritance. If that's not possible you may be better off with a different pattern like mixins. This post has some good examples: [Calling parent class __init__ with multiple inheritance, what's the right way?](https://stackoverflow.com/questions/9575409/calling-parent-class-init-with-multiple-inheritance-whats-the-right-way). – Mark Apr 24 '21 at 03:52
  • "Can I perform multiple inheritance(python 3) using the super keyword if my child class inherits more than 1 class?" Yes, that is actually the entire point of super, to facilitate cooperative multiple inheritance. See this talk: https://m.youtube.com/watch?v=EiOglTERPEo – juanpa.arrivillaga Apr 24 '21 at 04:12

0 Answers0