0
with open(argv[1],"r") as inp:
    reader = csv.DictReader(inp)
    for row in reader:
        lis = row["name"].split()
        print(len(lis))
        if (len(lis) == 2):
            print(row["house"], row["birth"])
            db.execute("INSERT INTO students (first, middle, last, house, birth) VALUES (?,NULL,?, ?,?)", lis[0], lis[1], row["house"], row["birth"])
            #TODO
        else:
            db.execute("INSERT INTO students (first, middle, last, house, birth) VALUES (?, ?, ?. ?, ?)", lis[0], lis[1], lis[2], row["house"], row["birth"])

it gives me the following error for only people with first middle and last names:

Traceback (most recent call last):
  File "import.py", line 19, in <module>
    db.execute("INSERT INTO students (first, middle, last, house, birth) VALUES (?, ?, ?. ?, ?)", lis[0], lis[1], lis[2], row["house"], row["birth"])
  File "/usr/local/lib/python3.7/site-packages/cs50/sql.py", line 21, in decorator
    return f(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/cs50/sql.py", line 372, in execute
    raise e
RuntimeError: no such column: Weasley.Gryffindor
2
  • Some things need another pair of eyes. Look carefully at the VALUES clause here ?, ?, ?. ?, ? – DinoCoderSaurus Mar 28 '20 at 20:21
  • Oh thanks a lot! – Varun Beluguli Mar 29 '20 at 6:07

You must log in to answer this question.

Browse other questions tagged .