Nov-18-2021, 12:13 PM
How can I pass an Enum into a constructor of a class? so the children classes can use it as well
I get an error message saying "Position is not accessed"
Thanks
class Employee(ABC5): employee_id = itertools.count(1000) def __init__(self,first_name,last_name,id_number,hours_worked,total_wage = 0,Position position): self.set_first_name(first_name) self.set_last_name(last_name) self.id_number = next(self.employee_id) self.set_hours_worked(hours_worked) self.total_wage = self.calculate_pay() self.position = self.position @abstractmethod def calculate_pay(self): pass def __str__(self): return '\nName: {} \nLastName: {} \nId Number: {} \nHours Worked: {} \nTotal Pay: {} \nPosition: {}'.format(self.first_name, self.last_name,self.id_number,self.hours_worked,self.calculate_pay(),self.position) class Operator(Employee): amount_per_hour = 9.80 def __init__(self,first_name,last_name,id_number,hours_worked,total_wage = 0): super().__init__(first_name,last_name,id_number,hours_worked,total_wage = 0) def calculate_pay(self): return round(self.amount_per_hour * self.hours_worked) def __str__(self): return super(Operator,self).__str__() class Position(enum.Enum): OPERATOR = "operator" SUPERVISOR = "supervisor" MANAGER = "manager"
I get an error message saying "Position is not accessed"
Thanks