Python class: Employee management system
<p>This exercise assumes that you have created the Employee class for Programming Exercise 4.
Create a program that stores Employee objects in a dictionary. Use the employee ID number
as the key. The program should present a menu that lets the user perform the following actions:
â¢ Look up an employee in the dictionary
â¢ Add a new employee to the dictionary
â¢ Change an existing employeeâs name, department, and job title in the dictionary
â¢ Delete an employee from the dictionary
â¢ Quit the program
When the program ends, it should pickle the dictionary and save it to a file. Each time the
program starts, it should try to load the pickled dictionary from the file. If the file does not
exist, the program should start with an empty dictionary.</p>

<p>Okay so here is my solution:-</p>

<pre><code>class Employee:
    'ID, number, department, job title'

    def __init__(self,ID,number,department,job_title):
        self.ID = ID
        self.number = number
        self.department = department
        self.job_title = job_title

    # Mutators

    def set_ID(self,ID):
        self.ID = ID

    def set_number(self,number):
        self.number = number

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

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

    #Accessor Methods

    def get_ID(self):
        return self.ID

    def get_number(self):
        return self.number

    def get_department(self):
        return self.department

    def get_job_title(self):
        return self.job_title

    def get_data(self):
        print self.ID, self.number,self.department,self.job_title
</code></pre>

<p>I saved the above as Employee.py in a folder. Then i started a new file and saved that as Employee Management System.py 
Here is the code in that file</p>

<pre><code>import Employee
import pickle

filename = 'contacts.dat'
input_file = open(filename,'rb')
unpickle_input_file = pickle.load(input_file)
def test_system():

    user = input('Press 1 to look up employee,\nPress 2 to add employee'
                 '\n3Press 3 to change an existing employee name, department and job title'
                 '\n4 Delete an employee from the dictionary'
                 '\n5 Quit the program'
                 '\nMake your choice ')

    if user == 2:
        ID = raw_input('Enter the name ')
        number = input('Enter the number')
        deparment = raw_input('Enter the department ')
        job_title = raw_input('Enter the job title ')

        entry = module from Employee??.class name(id,number,department,job_title)??
        empty_dictionary = {}
        empty_dictionary[number] = entry


input_file.close()
</code></pre>

<p>My first problem is that i am trying to use the created attribue in Employee.py . Specifically the <strong>init</strong> and add entry to it. I know the above code is not in the most logical forum but i am trying to first see if i can add data then pickle the file first. Everything else would be easy to figure out later if i can under how to do those two things.</p>

<p>It kind of reminds me of</p>

<pre><code>import math
x = math.pi(3.14)
x = module.function(3.14)
</code></pre>

<p>But i can't just seem to made the connection between the two examples.
Thank you</p>

<p>What you're trying to do is to instantiate an <code>Employee</code> object with the given parameters.  To do this, you just call the class name as if it were a function and pass in those parameters.  In your case, the class name is <code>Employee</code> within the <code>Employee</code> module, so you would do this:</p>

<pre><code>        entry = Employee.Employee(id, number, department, job_title)
</code></pre>

<p>This will create a new Employee object and call its <code>__init__</code> method with the parameters you passed in.</p>

python class object pickle