简体   繁体   中英

retrieve data sqlite3 into list python

I want to retrieve data from sqlite3 table, this is my code, but I only get an empty list. I checked my query on the sqlite3 and it works fine there.

import sqlite3
conn = sqlite3.connect("testee.db")
c = conn.cursor()
myquery = ("SELECT stock FROM testproduct WHERE store=3;")
c.execute(myquery)
templist=list(c.fetchall())

But templist is empty.

instead of extracting the execute statement in list, try this:

    rows=c.fetchall()
    for row in rows:
         print(row)

I found out the error just now. The database file in that directory was empty. I copied the filled in file to the directory python is running and it works fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM