1
 import sys
import cs50
# checking argv (that there's one and it's a csv)
if (len(sys.argv) != 2):
    sys.exit("Usage: roster.py house_name")
housename = sys.argv[1]
#print(house_name)
#open(f"students.db", "w").close()
db = cs50.SQL("sqlite:///students.db")
rows = db.execute("SELECT * FROM students WHERE house = 'housename' ORDER BY last ASC, first ASC")
for x in rows:
    print(x)

THANKS IN ADVANCE PSET 7 HOUSES 1)import.py in import.py task is to create a table and insert value from csv file after doing create a connection in roster.py and do select query MY ISSUE IS :- when i execute import.py it successfully create table but when i execute roster.py it display error ""no table found" secondly if i put all import.py code in roster.py then that error removed and got another issue i.e rows = db.execute("SELECT * FROM students WHERE house = sys.agv[1]") sysagv[1] is the name of house given at command line

0

First, you are not meant to create a table. Use the one already in the database as found in the download. Insert the data into that table, maybe DELETE FROM students to erase previous data, but do not change the table.

If you execute open(f"students.db", "w").close(), you erase the database and any tables. The table as found in the download got created by

CREATE TABLE students (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    first VARCHAR(255),
    middle VARCHAR(255),
    last VARCHAR(255),
    house VARCHAR(10),
    birth INTEGER
);

Instead of creating a new table to fix this mistake, you could also re-download the original database, like

rm -f students.db
wget https://cdn.cs50.net/2019/fall/psets/7/houses/houses/students.db

The rm -f would delete without asking first.

Second, you are asking for students with a house name of literally 'housename', not the content of variable housename.

Try the ? syntax, where the library would insert the variable value in a safe way.

rows = db.execute("... WHERE house = ? ORDER ...", housename)
| improve this answer | |
  • thanks for the guidelines got 100% – Hama Ijaz Mar 11 at 16:48

You must log in to answer this question.

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