简体   繁体   中英

Why the following code results in error?

It works for Employee and calculate_wage , but returns an error when I try to create an instance of PartTimeEmployee and call to the calculate_wage method of PartTimeEmployee 's parent class.

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))
return super(PartTimeEmployee, self).calculate_wage(self, hours)

is incorrect, it should be

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

And next time: Also post the error message you're seeing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM