0

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)
    
2
  • 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?. Commented Apr 24, 2021 at 3: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: m.youtube.com/watch?v=EiOglTERPEo Commented Apr 24, 2021 at 4:12

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.