为什么以下代码会导致错误?

时间:2013-10-05 10:42:46

标签: python

适用于Employeecalculate_wage,但在我尝试创建PartTimeEmployee的实例并调用calculate_wage PartTimeEmployee方法时会返回错误}的父类。

class Employee(object):
     """Models real-life employees!"""
     def __init__(self, employee_name):
         self.employee_name = employee_name

     def calculate_wage(self, hours):
         self.hours = hours
         return hours * 20.00

 class PartTimeEmployee(Employee):
     def __init__(self, employee_name):
         self.employee_name = employee_name
     def calculate_wage(self, hours):
         self.hours = hours
         return hours * 12.00
     def full_time_wage(self, hours):
         return super(PartTimeEmployee, self).calculate_wage(self, hours)

 milton = PartTimeEmployee("Milton")
 print (milton.full_time_wage(10))

1 个答案:

答案 0 :(得分:5)

return super(PartTimeEmployee, self).calculate_wage(self, hours)

不正确,应该是

return super(PartTimeEmployee, self).calculate_wage(hours)

下一次:同时发布您看到的错误消息。