[英]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. 我想从sqlite3表中检索数据,这是我的代码,但是我只得到一个空列表。 I checked my query on the sqlite3 and it works fine there. 我在sqlite3上检查了我的查询,在这里工作正常。
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: 而不是提取列表中的execute语句,请尝试以下操作:
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. 我将填充的文件复制到python正在运行的目录中,并且工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.