-1

here is the output

Enter your ID: 1234

Enter your NAME: Name
 
Enter your AGE: 20 

Enter your Birthdate: 12 

EMPLOYMENT STATUS:  
Enter 1 if you are employed:  
Enter 2 if unemployed:  

1 

Enter 1 if the employment is permanent:

Enter 2 if the employment a job-order: 

2

<__main__.Employee at 0x7f2358d89910>

None

the NONE keeps appearing, I want to get the information which is set by the user in display(employee_object) but I don't know hw


class Employee(object):

    # initialize values
    def __init__(self):
        self.id = ""
        self.name = ""
        self.age = ""
        self.birthdate = ""
        self.status = ""

    # setter methode for setting values to the class properties
    def set_id(self, id):
        self.id = id

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

    def set_age(self, age):
        self.age = age

    def set_birthdate(self, birthdate):
        self.birthdate = birthdate

    def set_status(self, status):
        self.status = status

    # getter methode for getting values of the class properties
    def get_id(self):
        return self.id

    def get_name(self):
        return self.name

    def get_age(self):
        return self.age

    def get_birthdate(self):
        return self.birthdate

    def get_status(self):
        return self.status


# methode which takes object as an argument and display its properties
def display(employee_object):
    print("ID : ", employee_object.get_id())
    print("Name : ", employee_object.get_name())
    print("Age : ", employee_object.get_age())
    print("Birthdate : ", employee_object.get_birthdate())
    print("Status : ", employee_object.get_status())

    # calls class Employee
    # Main methode of the program


if __name__ == "__main__":
    employee_List = []

    emp_1 = Employee()

    # appending objects to the list
    employee_List.append(emp_1)

    # Initializing each objects of the list
    for employee in employee_List:
        emp_id = input("Enter your ID: ")
        employee.set_id(emp_id)
        emp_name = input("Enter your NAME: ")
        employee.set_name(emp_name)
        emp_age = input("Enter your AGE: ")
        employee.set_age(emp_age)
        emp_birthdate = input("Enter your Birthdate: ")
        employee.set_birthdate(emp_birthdate)
        emp_stat1 = input("EMPLOYMENT STATUS: \nEnter 1 if you are employed: \nEnter 2 if unemployed: \n")
        if emp_stat1 == '1':
            emp_stat2 = input("Enter 1 if the employment is permanent: \nEnter 2 if the employment a job-order: \n")
            if emp_stat2 == '1':
                employee.set_status = "PERMANENT"
            elif emp_stat2 == '2':
                employee.set_status = "JOB ORDER"
        elif emp_stat1 == '2':
            emp_stat2 = input("Enter 1 if you are a freelancer: \nEnter 2 if you are seeking a job: \n ")
            if emp_stat2 == '1':
                employee.set_status = "FREELANCER"
            elif emp_stat2 == '2':
                employee.set_status = "JOB SEEKER"

    # Displaying each objects of the list
    for employee_object in employee_List:
        print(display(employee_object))
azro
  • 53,056
  • 7
  • 34
  • 70
  • Nobody is going to get that error again; likely not even you. You've got a specific class that's personal to your own code, and a memory address. It's not even an error, it's just the standard `__repr__` of a class – roganjosh Apr 10 '21 at 08:26
  • You should add your code into YOUR initial post, the question, below that the places for answers – azro Apr 10 '21 at 08:27

2 Answers2

0

As no return is specified in display method, the default is None , see How to prevent Python function from returning None

Your display method shows things, you don't expected it to return anything, so call it like

# Displaying each objects of the list
for employee_object in employee_List:
    display(employee_object)

Then some python-coding specifics

  • What's the pythonic way to use getters and setters? using @property

    # If you defined a self._name attribut
    
    @property
    def name(self):
        return self._name
    @name.setter
    def name(self, name):
        self._name = name
    
    # GET use : employee.name
    # SET use : employee.name = emp_name
    
  • Use a constructor with parameters, that nicer

    class Employee(object):
        def __init__(self, emp_id, name, age, birthdate, status):
            self._id = emp_id
            self._name = name
            self.age = age
            self.birthdate = birthdate
            self.status = status
    
  • Don't use a outer method display, there is a built-in way with __str__ (or __repr__) see Difference between __str__ and __repr__, add it to the Employee class and it'll be use then you do print(emp) where emp is an Employee instance

    def __str__(self):
        return "\n".join((
            f"ID: {self.id}",
            f"Name: {self.name}",
            f"Age: {self.age}",
            f"Birthdate: {self.birthdate}",
            f"Status: {self.status}",
        ))
    

Then the principe you used of create a list / add one instance / iterate on the list to populate the instance isn't a good idea, because you have a fixed amount of employee which isn't dynamically given.

I'd suggest to use a while loop that will stops when you enter stop at the ID input

employee_List = []

while True:
    emp_id = input("Enter your ID: ('stop' to quit)")

    if emp_id == "stop":
        break

    emp_name = input("Enter your NAME: ")
    emp_age = input("Enter your AGE: ")
    emp_birthdate = input("Enter your Birthdate: ")
    emp_stat1 = input("EMPLOYMENT STATUS: \nEnter 1 if you are employed: \nEnter 2 if unemployed: \n")
    if emp_stat1 == '1':
        emp_stat2 = input("Enter 1 if the employment is permanent: \nEnter 2 if the employment a job-order: \n")
        if emp_stat2 == '1':
            emp_status = "PERMANENT"
        elif emp_stat2 == '2':
            emp_status = "JOB ORDER"
    elif emp_stat1 == '2':
        emp_stat2 = input("Enter 1 if you are a freelancer: \nEnter 2 if you are seeking a job: \n ")
        if emp_stat2 == '1':
            emp_status = "FREELANCER"
        elif emp_stat2 == '2':
            emp_status = "JOB SEEKER"

    emp = Employee(emp_id, emp_name, emp_age, emp_birthdate, emp_status)
    employee_List.append(emp)

for employee_object in employee_List:
    print(employee_object, "\n")

FULL CODE

azro
  • 53,056
  • 7
  • 34
  • 70
  • <__main__.Employee at 0x7f2358e65d90> I get this when I uses that code – Frenchie Estoquia Chua Apr 10 '21 at 08:35
  • @FrenchieEstoquiaChua I've just finished my code. You should never have the output you show me, as it is the result of printing an Employee class without have defining `__str__` or `__repr__` and you don't have such – azro Apr 10 '21 at 08:53
0

When using print, python will call the str method of your class, therefore if you want to print readable information you can do it by using

print(employee_object)

and inserting the str method to your class, which could be something like:

def __str__(self):
    return f'The employee {self.name} is {self.status}'
Gaussian97
  • 137
  • 1
  • 9