I keep getting a key-error in pset7, Houses:
Traceback (most recent call last): File "import.py", line 24, in <module> names = cutting(row["name"]) KeyError: 'name'
This key exists in the csv file though, and I did use
reader = csv.DictReader(argv, "r")
to open the csv file as a dictionary, so I'm confused as to why it says it doesn't exist. This is my iteration:
for row in reader: names = cutting(row["name"]) house = row["house"] birth = row["birth"] db.execute("INSERT INTO students (first, middle, last, house, birth) VALUES (?, ?, ?, ?, ?)", names, names, names, house, birth)
# FUNCTION TO CUT def cutting(name): # SPLIT THE NAME INTO DIFFERENT SEGMENTS BY SPACE names = name.split() # RETURN AS IS IF THERE IS A MIDDLE NAME return names if len(names) == 3 else [names, None, names]