Commit 409607e4 by Patryk Czarnik

zmiany we wczytywaniu

parent 01739a80
# W tym pliku mamy definicję klasy Employee - obiekt tej klasy reprezentuje jednego pracownika i zawiera jego dane.
# Mamy też funkcje odpowiedzialne za odczyt i zapis danych z/do pliku csv.
class Employee: class Employee:
def __init__(self, employee_id, first_name, last_name, job_title, salary, hire_date, department_name, address, postal_code, city, country): def __init__(self, employee_id, first_name, last_name, job_title, salary, hire_date, department_name, address, postal_code, city, country):
self.employee_id = employee_id self.employee_id = int(employee_id)
self.first_name = first_name self.first_name = first_name
self.last_name = last_name self.last_name = last_name
self.job_title = job_title self.job_title = job_title
self.salary = salary self.salary = int(salary)
self.hire_date = hire_date self.hire_date = hire_date
self.department_name = department_name self.department_name = department_name
self.address = address self.address = address
...@@ -25,10 +22,7 @@ def read_csv(file_path='emps.csv'): ...@@ -25,10 +22,7 @@ def read_csv(file_path='emps.csv'):
with open(file_path, mode='r', encoding='utf-8') as file: with open(file_path, mode='r', encoding='utf-8') as file:
file.readline() file.readline()
for line in file: for line in file:
t = line.strip().split(';') emps.append(Employee(*(line.strip().split(';'))))
emp = Employee(int(t[0]), t[1], t[2], t[3], int(t[4]),
t[5], t[6], t[7], t[8], t[9], t[10])
emps.append(emp)
return emps return emps
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment