Exception occurred in Python multi-inheritance band parameters

1 there is an exception in the process of learning python multi-inheritance. I really don"t know what the problem is. Ask for a solution

.
class People(object):
    def __init__(self,name,sex):
        self.name=name
        self.sex=sex
class Teacher(People):
    def __init__(self, name, sex, student):
        super(Teacher, self).__init__(name, sex)
        self.student=student
class Father(People):
    def __init__(self,name,sex,child):
        super(Father,self).__init__(name,sex)
        self.child=child
class Disen(Father,Teacher):
    def __init__(self,name,sex,child,student):
        super(Disen,self).__init__(name,sex,child)
        super(Disen,self).__init__(name,sex,student)
print(Disen.__mro__)
disen=Disen("disen_","male","judy","student1")

exception code
F:MypythonProjectvenvScriptspython.exe F:/MypythonProject/my_file.py class /
(< class"_ main__.Disen" >, < class"_ main__.Father" >, < class"_ main__.Teacher" >, < class"_ main__.People" >, < class" object" >)
Traceback (most recent call last):
File "F:/MypythonProject/my_file.py", line 185, in < module >

disen=Disen("disen_","male","judy","student1")

File "F:/MypythonProject/my_file.py", line 182, in init

super(Disen,self).__init__(name,sex,child)

File "F:/MypythonProject/my_file.py", line 178, in init

super(Father,self).__init__(name,sex)

TypeError: _ init__ () missing 1 required positional argument: "student"
question:
1 during debugging, when the Disen class instance executes the constructor, the constructor of the Father class is first called, but the error indicates that the Father class lacks a student attribute, which is defined in the Teacher class. I really don"t know. This should be because I can"t understand diamond inheritance. I hope God can explain the concept of diamond inheritance in combination with my error. Thank you

Feb.28,2021

first of all, multiple inheritance and multi-level inheritance should be avoided, otherwise the quality of the code will be greatly reduced. Learn about component programming and interface programming .

in this example, you can explicitly call the _ _ init__ () method of the parent class instead of super () , as follows

-sharp -*- coding: utf-8 -*-
class People(object):
    def __init__(self, name, sex):
        self.name = name
        self.sex = sex


class Teacher(People):
    def __init__(self, name, sex, student):
        People.__init__(self, name, sex)
        self.student = student


class Father(People):
    def __init__(self, name, sex, child):
        People.__init__(self, name, sex)
        self.child = child


class Disen(Father, Teacher):
    def __init__(self, name, sex, child, student):
        Father.__init__(self, name, sex, child)
        Teacher.__init__(self, name, sex, student)


def test_class():
    -sharp  pytest 
    disen = Disen('', '', 'judy', 'student1')
    assert disen.name == ''
    assert disen.sex == ''
    assert disen.child == 'judy'
    assert disen.student == 'student1'
Menu