title: Python: how to initialize 2 superclasses using super()?
body: <p>I have two superclasses, Father and Mother and they will be inherited by Child.</p>
  
  <pre><code>class Father:
    def __init__(self, **kwargs):
      self.fathername = kwargs["ffn"] + " " + kwargs["fln"]
      self.fatherage = kwargs["fa"]
  
  class Mother:
    def __init__(self, **kwargs):
      self.mothername = kwargs["mfn"] + " " + kwargs["mln"]
      self.motherage = kwargs["ma"]
  </code></pre>
  
  <p>Here class Child inherits from Father and Mother</p>
  
  <pre><code>class Child(Father, Mother):
    def __init__(self, **kwargs):
      self.name = kwargs["name"] + " " + kwargs["lastname"]
      self.age = kwargs["age"]
  </code></pre>
  
  <p>I can initialize Father and Mother if I call their <code>__init__()</code>s separately. </p>
  
  <pre><code>    Father.__init__(self, **kwargs)
      Mother.__init__(self, **kwargs)
  </code></pre>
  
  <p>But how do I achieve the same with super()? If I call it like below, it only initializes Father and not Mother (because Father is the next one in the MRO I assume)</p>
  
  <pre><code>    super().__init__(**kwargs)
  </code></pre>
  
  <p>Below is just the <code>__str__()</code> overridden to show what was assigned. </p>
  
  <pre><code>def __str__(self):
      return \
      "Im {}, {} years old".format(self.name, self.age) + "\n" + \
      "My dad is {} and he is {} years old".format(self.fathername, self.fatherage) + "\n" + \
      "My mom is {} and she is {} years old".format(self.mothername, self.motherage)
  
  familyname = "Simpson"
  child = Child(**{"name": "Bart", "lastname": familyname, "age": 15, "ffn": "Hommer", "fln": familyname, "fa": 54, "mfn": "Marggie", "mln": familyname, "ma": 46})
  </code></pre>
  
  <p>When I try to print the object, it will fail because Mother superclass was never initialized (when I used <code>super()</code> in the Child <code>__init__()</code>)</p>
  
  <pre><code>print(child)
  
  The program raises a runtime error
  
  Traceback (most recent call last):
    File "/tmp/pyadv.py", line 225, in &lt;module&gt;
      print(child)
    File "/tmp/pyadv.py", line 217, in __str__
      return     "Im {}, {} years old".format(self.name, self.age) + "\n" +     "My dad is {} and he is {} years old".format(self.fathername, self.fatherage) + "\n" +     "My mom is {} and she is {} years old".format(self.mothername, self.motherage)
  AttributeError: 'Child' object has no attribute 'mothername'
  </code></pre>
  
  <p>So, how do I use super to initialize two superclasses?</p>
  
  <p>EDIT:
  I tried to add <code>super(Father, self).__init__(**kwargs)</code> and <code>super(Mother, self).__init__(**kwargs)</code> to the superclasses <code>__init__()</code> methods but I got the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/tmp/pyadv.py", line 225, in &lt;module&gt;
      child = Child(**{"name": "Bart", "lastname": familyname, "age": 15, "ffn": "Hommer", "fln": familyname, "fa": 54, "mfn": "Marggie", "mln": familyname, "ma": 46})
    File "/tmp/pyadv.py", line 217, in __init__
      super().__init__(**kwargs)
    File "/tmp/pyadv.py", line 199, in __init__
      super(Father, self).__init__(**kwargs)
    File "/tmp/pyadv.py", line 208, in __init__
      super(Mother, self).__init__(**kwargs)
  TypeError: object.__init__() takes no parameters
  </code></pre>
  
  <p>I also tried to add <code>super(Father, self).__init__()</code> and <code>super(Mother, self).__init__()</code> (no arguments inside <code>__init__()</code>) to the superclasses <code>__init__()</code> methods but I then got the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/tmp/pyadv.py", line 225, in &lt;module&gt;
      child = Child(**{"name": "Bart", "lastname": familyname, "age": 15, "ffn": "Hommer", "fln": familyname, "fa": 54, "mfn": "Marggie", "mln": familyname, "ma": 46})
    File "/tmp/pyadv.py", line 217, in __init__
      super().__init__(**kwargs)
    File "/tmp/pyadv.py", line 199, in __init__
      super(Father, self).__init__()
    File "/tmp/pyadv.py", line 206, in __init__
      self.mothername = kwargs["mfn"] + " " + kwargs["mln"]
  KeyError: 'mfn'
  </code></pre>
  
  <p>Solution 1:
  @blkkngt strip-off below</p>
  
  <p>Solution 2:
  Root superclass, detailed <a href="https://rhettinger.wordpress.com/2011/05/26/super-considered-super/" rel="nofollow noreferrer">here</a>. </p>
  
  <pre><code>class Root:
    def __init__(self, **kwargs):
      pass
  
  class Father(Root):
    def __init__(self, **kwargs):
      self.fathername = kwargs["ffn"] + " " + kwargs["fln"]
      self.fatherage = kwargs["fa"]
      super().__init__(**kwargs)
  
  class Mother(Root):
    def __init__(self, **kwargs):
      self.mothername = kwargs["mfn"] + " " + kwargs["mln"]
      self.motherage = kwargs["ma"]
      super().__init__(**kwargs)
  
  class Child(Father, Mother):
    def __init__(self, **kwargs):
      self.name = kwargs["name"] + " " + kwargs["lastname"]
      self.age = kwargs["age"]
      super().__init__(**kwargs)
    def __str__(self):
      return \
      "Im {}, {} years old".format(self.name, self.age) + "\n" + \
      "My dad is {} and he is {} years old".format(self.fathername, self.fatherage) + "\n" + \
      "My mom is {} and she is {} years old".format(self.mothername, self.motherage)
  
  familyname = "Simpson"
  child = Child(**{"name": "Bart", "lastname": familyname, "age": 15, "ffn": "Homer", "fln": familyname, "fa": 54, "mfn": "Marge", "mln": familyname, "ma": 46})
  
  print(child)
  </code></pre>