#14 This Looks Like Job For


#1

So I created the code for this lesson and is passes:

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 calculate_wage(self, hours):
    self.hours = hours
    return hours * 12.00
  def full_time_wage(self, hours):
    return super(PartTimeEmployee, self).calculate_wage(hours)
  
milton = PartTimeEmployee("Milton")
print milton.full_time_wage(10)

but what I don’t understand is why my super of calculate_wage only calls hours instead of both self and hours like the one in the base class. Also, the program allowed this code to pass but the console showed the error “python:1: SyntaxWarning: import * only allowed at module level”. What does this mean?


#2

this an error you can safely ignore, its not related to your code

the first parameter (self) of methods is the instance the method is called on, let me show you what i mean:

class Example(object):
    def example_method(self):
        print "hello world"

e = Example()
// calling method on instance
e.example_method()
// calling method on class
Example.example_method(e)

i create a class, then i create an instance (e)

then i call the method on the instance, given we call the method on an instance, python is handling self.

Then, i call the method on the class itself, but i need to pass an instance (to satisfy self parameter)

so when we call methods on instance, which we do here:

  def full_time_wage(self, hours):
    return super(PartTimeEmployee, self).calculate_wage(hours)

we don’t need to supply an argument for self, python is handling it given we call the method on an instance.


#3

I think I understand, thank you!


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.