Teile 10 bis 12.
This commit is contained in:
29
teil10/read_csv.py
Normal file
29
teil10/read_csv.py
Normal file
@@ -0,0 +1,29 @@
|
||||
school = []
|
||||
class Lehrer():
|
||||
|
||||
def __init__(self, vorname, name):
|
||||
self.vorname = vorname
|
||||
self.name = name
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.vorname} {self.name}'
|
||||
|
||||
|
||||
try:
|
||||
|
||||
with open('namen.csv','r') as f:
|
||||
for line in f:
|
||||
splitted = line.strip().split(',')
|
||||
name = splitted[0]
|
||||
vorname = splitted[1]
|
||||
|
||||
lehrer = Lehrer(vorname,name)
|
||||
school.append(lehrer)
|
||||
|
||||
|
||||
except IOError as x:
|
||||
print(f'I/O-Fehler: {x}')
|
||||
|
||||
print(school)
|
||||
print(school[0])
|
||||
print(school[3])
|
Reference in New Issue
Block a user