TypeError:__Init __()获得了4个位置论点,但给出了7个


class Employee(object):
    def __init__(self,ename,salary,dateOfJoining):
        self.ename=ename
        self.salary=salary
        self.dateOfJoining=dateOfJoining
    def output(self):
        print("Ename: ",self.ename,"nSalary: ",self.salary,"nDate Of 
Joining: ",self.dateOfJoining)
class Qualification(object):
    def __init__(self,university,degree,passingYear):
        self.university=university
        self.degree=degree
        self.passingYear=passingYear
    def qoutput(self):
        print("Passed out fom University:",self.university,"nDegree:",self.degree,"Passout year: ",self.passingYear)
class Scientist(Employee,Qualification):
    def __int__(self,ename,salary,dateOfJoining,university,degree,passingYear):
        Employee.__init__(self,ename,salary,dateOfJoining)
        Qualification.__init__(self,university,degree,passingYear)
    def soutput(self):
        Employee.output()
        Qualification.output()
a=Scientist('Ayush',20000,'21-04-2010','MIT','B.Tech','31-3-2008')
a.soutput()

我无法解决该问题的解决方案,我无法理解为什么会发生这种tpyeerror。我是Python的新手。谢谢

您的科学家班级将INIT函数写为:

def __int__

而不是

def __init__

因此,发生的事情是它从其父类中继承了INIT函数,该函数接收到较少的参数,然后您发送到类。

另外,您还不应该使用超级功能的父母来调用父母的初始

super(PARENT_CLASS_NAME, self).__init__()

这显然适用于所有父函数。

您的科学家类构造函数被拼写为__int__而不是__init__。由于没有从科学家班级使用的构造函数,因此它在继承链上提高了一个级别,并使用了员工的构造函数,实际上,这实际上只使用了4个位置参数。只需修复错字即可工作。

(您在代码中还有其他一些不好的事情,但我会允许其他人对提示发表评论(

相关内容

最新更新