Commit e3615cb3 by Patryk Czarnik

emps_obiektowo - pierwsze przykłady

parent 6a559262
......@@ -26,6 +26,7 @@ def read_csv(file_path='emps.csv'):
file.readline()
for line in file:
t = 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])
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
from employees import read_csv
# Wszystkie szczegóły związane z dostępem do pliku, są ukryte w tej funkcji
emps = read_csv('emps.csv')
# Aby wykonać operacje "dla każdego pracownika", wykonujemy pętlę po elementach listy `emps`.
# Pojedynczy element `emp` to obiekt klasy `Employee`, a dane pracownika są dostępne3 w postaci atrybutów tego obiektu,
# np. `.first_name`, `.salary`
for emp in emps:
print(f'Pracownik {emp.first_name} {emp.last_name} ({emp.job_title}) zarabia ${emp.salary}')
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