Assuming this:
class Father():
def __init__(self,fathername):
self.papa = f"The father is {fathername.upper()}"
class Mother():
# Mother class is COMPLETELY DIFFERENT AS Father.
# The important thing is that they both built an attribute each.
def __init__(self,mothername):
self.mama = f"the mother is {mothername.lower()}"
class Child3(Father,Mother):
def __init__(self,name,fathername,mothername):
Father.__init__(self,fathername)
Mother.__init__(self,mothername)
self.name=name
both of the following works:
c = Child3('Noa',fathername='J',mothername='M')
c = Child3('Noa','J','M')
So far so good. But assuming I want to inherit from several classes (not multiple nesting inheritances but just one class inheriting from several ones that don't inherit from anything else) How can I use super() to initialise the parent classes?
The following does not work:
class Child4(Father,Mother):
def __init__(self,name,fathername,mothername):
super().__init__(self,fathername=fathername,mothername=mothername)
self.name=name
TypeError: init() got multiple values for argument 'fathername'
Some previous consultations:
How does Python's super() work with multiple inheritance? This is a very complete with very nice answers which I already voted up some time ago. Nevertheless this question is a bit different and not entirely the case I am asking here, i.e. MRO (Method resolution order) is of no importance here. I would like to achieve a way to hard code initialise the parent classes to access all of the attributes. In the mentioned question the answer with the most votes does not have attributes in the parent classes. In the second most voted answer the parent classes DO NOT HAVE ATTRIBUTES neither. Yet in another of the answers there is a very complete explanation of MRO with multi inheritance, which again, is not the point here since there is one one level of inheritance.
In this other question with a lot of positive up votes there is no attributes of the parents classes neither: Calling parent class __init__ with multiple inheritance, what's the right way?
This is the one coming closer, but not implementing a solution with super() Python - Calling __init__ for multiple parent classes actually suggesting going away from inheritance paradigm
This is a close one: calling init for multiple parent classes with super? but I see there there is super() in the parent classes which is counter productive since the aim is not having to modify the parent classes.
In order to understand the use of this example and why I HAVE TO USE inheritance think that the first parent class calls an API and performs a couple of 1000s code NLP process to extract data of the API response. The same goes for the second parent class. Then the child class will try to get insights comparing both further using NLP.
The classes Mother and Father are given. They are not coded by me. I don't have a chance to modify them. They don't depend on any other class.