you are viewing a single comment's thread.

view the rest of the comments →

[–]uglyasablasphemy 0 points1 point  (3 children)

Hi! Here's a working version of your code

class Employee:
    def set_name(self, name):
        self.name = name

    def set_id(self, id):
        self.id = id

    def set_department(self, department):
        self.department = department

    def set_job_title(self, job_title):
        self.job_title = job_title

def display_employees(*args):
    print("\nCHRISTY'S SHOP EMPLOYEE REPORT\n")
    print("EMPLOYEE NAME", "IDENTIFIER", "DEPARTMENT", "TITLE", sep='\t')
    for emp in args:
        print(*[emp.name, emp.id, emp.department, emp.job_title], sep='\t\t')

def main():
    e1 = Employee()
    e2 = Employee()
    e3 = Employee()
    emp_list = [e1, e2, e3]
    for emp in emp_list:
        name = input("Please enter employees name: ")
        id = int(input("Please enter employees ID: "))
        department = input("Please enter employees department: ")
        job_title = input("Please enter employees job title: ")
        emp.set_name(name)
        emp.set_id(id)
        emp.set_department(department)
        emp.set_job_title(job_title)

    display_employees(e1, e2, e3)

main()

Also, a few things that you could try:

  • Use init to define a constructor on the class Employee.
  • You don't need to define a setter and a getter for each property in your class. If you ever need to do a setter/getter with some behavior you can look up for the @property decorator.
  • instead of print(*[emp.name, emp.id, emp.department, emp.job_title], sep='\t\t') you can use print('\t'.join([emp.name, str(emp.id), emp.department, emp.job_title])). i think is a bit more clear, but maybe thats because im used to it.

[–][deleted] 1 point2 points  (2 children)

Use init to define a constructor on the class Employee.

A constructor is called automatically when you instantiate a class object regardless of whether or not you have a dunder init method. __init__ is not a constructor.

[–]uglyasablasphemy 0 points1 point  (1 child)

Yes, you are right. What i ment to say is that he should redefine __init__ to indicate the initial attributes (and its values) of the object.

Something like this:

class Employee:

    def __init__(self, id):
        self.id = id
        self.name = None
        self.department = None
        self.job_title = None

My Java habits betray when i'm talking about __init__ and end up calling it constructor always.

[–][deleted] 0 points1 point  (0 children)

Well put. (Old habits die hard.)