Sorry being a noob, it might be a silly mistake but i am new to python so please help.
I want to have a list of entity in python. For entity, I am using a dictionary. EntityList.py is like this.
from EmployeeEntity import Entity
class AddEmployee:
def AddEmployeeByUserInput(self):
EmployeeList = []
while (input('Do you want to enter an entry y/n:') == 'y'):
objEmployee = Entity.employee
objEmployee['id'] = input('Enter id: ')
objEmployee['fname'] = input('Enter first name: ')
objEmployee['lname'] = input('Enter last name: ')
objEmployee['address'] = input('Enter city: ')
objEmployee['contact'] = input('Enter contact number: ')
EmployeeList.append(objEmployee)
print(EmployeeList)
objAddEmployee = AddEmployee()
objAddEmployee.AddEmployeeByUserInput()
EmployeeEntity.py is like this.
class Entity:
employee = {'id':'',\
'fname':'',\
'lname':'',\
'address':'',\
'contact':''}
This is what i am entering & what i am getting as an output.
Do you want to enter an entry y/n:y
Enter id: 1
Enter first name: Brijesh
Enter last name: Parekh
Enter city: Ahmedabad
Enter contact number: 7545454574
Do you want to enter an entry y/n:y
Enter id: 2
Enter first name: Kandarp
Enter last name: Mehta
Enter city: Bhavnagar
Enter contact number: 3845735375
Do you want to enter an entry y/n:n
[{'id': '2', 'fname': 'Kandarp', 'address': 'Bhavnagar', 'lname': 'Mehta', 'contact': '3845735375'}, {'id': '2', 'fname': 'Kandarp', 'address': 'Bhavnagar', 'lname': 'Mehta', 'contact': '3845735375'}]
My last entered details overwrite all the old ones.