Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Enum help
#1
How can I pass an Enum into a constructor of a class? so the children classes can use it as well
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
Reply


Messages In This Thread
Enum help - by SephMon - Nov-18-2021, 12:13 PM
RE: Enum help - by Larz60+ - Nov-18-2021, 11:09 PM
RE: Enum help - by SephMon - Nov-19-2021, 12:00 AM
RE: Enum help - by Yoriz - Nov-19-2021, 09:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable sorting methods for Enum DataClasses koen 1 813 May-30-2023, 07:31 PM
Last Post: deanhystad
  Alarm system with state, class, enum. Frankduc 0 1,308 May-04-2022, 01:26 PM
Last Post: Frankduc
Question Having trouble writing an Enum with a custom __new__ method stevendaprano 3 4,269 Feb-13-2022, 06:37 AM
Last Post: deanhystad
  enum from typelib Erhy 2 2,187 Jan-26-2019, 05:37 PM
Last Post: Erhy
  Python error? Enum and strings tycarac 3 3,623 Dec-15-2018, 10:39 AM
Last Post: tycarac

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020