Hot answers tagged

3

The pset requires a table names students (plural). That is how the distro database is configured. It looks like this program is looking for a table named student singular, based on this INSERT INTO student. Here is the create table statement from the distro code: CREATE TABLE students ( id INTEGER PRIMARY KEY AUTOINCREMENT, first VARCHAR(255), ...


2

The None keyword is used to define a null value, or no value at all. When you put none in ' ' , it becomes a string. Remove the ' ' and it should work fine. Have a great day!.


1

Just check your database. I guess the data has been imported 4 times because of which each name has been printed 4 times. There is no real problem with any of your code. Hope this helps you. If it does then please check the tickmark.


1

This with open("characters.csv", "r") is a problem. Why take an argument and not use it? Don't hard code the file name.


1

I just figured it out on the INSERT INTO am inserting variables so I have to format the string or in a better way use the "?" place holder so avoid SQL injections db.execute("INSERT INTO students (first, middle, last, house, birth) VALUES (?, ?, ?, ?, ?)", name[0], None, name[1],house, birth)


1

Maybe a typo? == is not the set operator, it is the relational operator. This row['middle'] == "" evaluates to False; it does not change the value of row['middle'].


1

The CASE is the fourth column in the select, so it needs a , after birth. That will fix the syntax error. It may not, however, give you the result you are looking for :) The number of columns returned by a query is fixed. A column cannot be optionally selected. Assuming this is for the roster problem, a different approach would be to select middle in the ...


1

Fixed the errors import.py : The name check for characters.csv was too specific. Needed to check only for file format of .csv roster.py : Extra space after each line Thanks for your help :D


1

Since program uses the sqlite3 python interface (not the CS50 SQL interface), any changes to the database need to be committed in order to persist. From the python sqlite interface doc: commit() This method commits the current transaction. If you don’t call this method, anything you did since the last call to commit() is not visible from other ...


1

Use the template syntax, somewhat similar to printf format strings. db.execute("INSERT INTO students (first, middle, last) VALUES (?, ?, ?)", lis[0], lis[1], lis[2]) The template syntax makes sure the values are passed in a safe way, encoded according to their type, so that none of the values end up being treated as SQL commands. Other solutions like ...


1

Assume error comes at if (len(lis) == 2): (there are two "len" in the program). The problem is here lis = row["name"].split, because it is not calling the split function. It is declaring lis a function (use print(lis()) to see it in action). The correct syntax would be lis = row["name"].split(). Spoiler alert: program names the array lis, but is using ...


1

executemany is included in the python sqlite3 library, but not in the cs50 SQL library. One option would be to iterate over the dict and insert one row at a time.


Only top voted, non community-wiki answers of a minimum length are eligible