0
import cs50
import sys
import sqlite3

db = sqlite3.connect("students.db")
house_reader = db.cursor()

if len(sys.argv) != 2:
    print('Usage: import.py file.csv')
    exit()
house_reader.execute("SELECT first, middle, last, birth FROM students WHERE house = ? ORDER BY last, first", [sys.argv[1]])     
row = house_reader.fetchone()
house_reader.execute("SELECT first, middle, last, birth FROM students WHERE house = ? ORDER BY last, first", [sys.argv[1]]) 
row = house_reader.fetchone()
for row in house_reader:
    if row[1] == None:
        print(f"{row[0]} {row[2]}, born {row[3]}")
    else:
        print(f"{row[0]} {row[1]} {row[2]}, born {row[3]}")
0

This

house_reader.execute("SELECT first, middle, last, birth FROM students WHERE house = ? ORDER BY last, first", [sys.argv[1]])     
row = house_reader.fetchone()

gets the first row. Then doesn't do anything with it.

This

house_reader.execute("SELECT first, middle, last, birth FROM students WHERE house = ? ORDER BY last, first", [sys.argv[1]]) 
row = house_reader.fetchone()

gets the second row and gives output based on the if.

If program uses the sqlite3 library (which this does), look into fetchall.

If program uses the cs50 library, then iterate through the execute result.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .