Reputation: 2719
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()
I'm not able to get a solution to the problem and I'm not able to understand why this TpyeError has occured. I'm new to python. Thanks
Upvotes: 0
Views: 5212
Reputation: 1851
Your Scientist class constructor is misspelled as __int__
instead of __init__
. Since there is no overridden constructor to be used from the Scientist class, it goes up a level on the inheritance chain and uses the Employee's constructor, which in fact only uses 4 positional arguments. Just fix the typo and it should work.
(there are a few other bad things you're doing with classes in your code, but I'll allow other people to comment with tips)
Upvotes: 1
Reputation: 814
Your scientist class has the init function written as :
def __int__
instead of
def __init__
So what happened is it inherited the init function from its parent class, which receives less params then you sent to the class.
Also instead of calling the init of the parents you should be using the super function.
super(PARENT_CLASS_NAME, self).__init__()
This obviously goes for all parent functions.
Upvotes: 5