I'm trying to read from file. Everything works, but I got the key error in spite of the fact that they key exist in debugger. I saw very similiar codes working but I don't have any idea why I got KeyError
when I reach "id_samolotu"
. My code:
import csv
from lot import DatabaseofLoty, Lot
def read_from_csv(path):
loty = []
with open(path,"r") as file_handle:
reader = csv.DictReader(file_handle)
for row in reader:
numer_lotu = row["numer_lotu"]
id_samolotu = row["id_samolotu"]
czas_lotu = row['czas_lotu']
trasa = row['trasa']
wolne_miejscaek = row['wolne_miejscaek']
wolne_miejscabiz = row['wolne_miejscabiz']
wolne_miejscapr = row['wolne_miejscapr']
bramka = row['bramka']
lot = Lot(numer_lotu, id_samolotu, czas_lotu, trasa, wolne_miejscaek,
wolne_miejscabiz, wolne_miejscapr, bramka)
loty.append(lot)
database = DatabaseofLoty(loty)
read_from_csv("loty.txt")
loty.txt
file:
numer_lotu, id_samolotu, czas_lotu, trasa, wolne_miejscaek, wolne_miejscabiz, wolne_miejscpr, bramka
1, 3, 3:52, Amsterdam-Berlin, 129, 92, 192, 8