Question is the same as above, I just don't know how to get it to print the 4 rows that contain London. Here is my code for reference:
def db():
import sqlite3
con = sqlite3.connect('weather.db')
global cur
cur = con.cursor()
cur.execute("CREATE TABLE if not exists weather(City text,Country text,Season text,Temperature int,Rainfall int)")
weather_list = [['Mumbai','India',1,24.8,5.9],['Mumbai','India',2,28.4,16.2],['Mumbai','India',3,27.9,1549.4],['Mumbai','India',4,27.6,346.0],['London','UK',1,4.2,207.7],['London','UK',2,8.3,169.6],['London','UK',3,15.7,157.0],['London','UK',4,10.4,218.5],['Cairo','Egypt',1,13.6,16.5],['Cairo','Egypt',2,20.7,6.5],['Cairo','Egypt',3,27.7,0.1],['Cairo','Egypt',4,22.2,4.5]]
for items in weather_list:
items = tuple(items)
cur.execute("INSERT INTO weather VALUES(?,?,?,?,?)",items)
con.commit()
for items in cur.fetchall():
print(items)
#4
def db_changes():
db()
global cur
cur.execute('SELECT City FROM weather WHERE City=?',(['London']))
for record in cur:
print(record)
Aucun commentaire:
Enregistrer un commentaire