I am trying to make a class, to store the biography data of employees and store them in a dictionary, as you can see.
I want to ask if it is a bad practice to change class variables. If yes, please explain why it is so. And what can be perfect way of doing the thing I am doing?
# Defining a class for storing the information related to the instructors at bcoder company
class Employee:
company_records = {}
Employee_count = 0
def __init__(self, fname, lname, email_id, contact, gender):
self.fname = fname
self.lname = lname
self.email_id = email_id
self.contact = contact
self.gender = gender
self.add_records()
# Defining a function for returning the full name of our employee
def fullname(self):
return("{} {}".format(self.fname, self.lname))
def add_records(self):
Employee.Employee_count += 1
Employee.company_records[Employee.Employee_count] = {
"Name": self.fullname(),
"Email_id": self.email_id,
"Contact": self.contact,
"Gender": self.gender
}
emp_1 = Employee("Vaibhav", "Yadav", "vaibhavy1912@gmail.com", 9432098712, "Male")
print(emp_1.fullname())
print(Employee.company_records)
emp_2 = Employee("vaibhav", "Gupta", "hg1123@gmail.com", 9323118976, "male")
print(Employee.company_records)
emp_2 = Employee("Yogesh", "Yadav", "yogesh1123@gmail.com", 9323118976, "male")
print(Employee.company_records)
What is an elegant way of doing the above thing?