将数据从sqlite3提取到python列表中

2024-06-28 11:18:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从sqlite3表中检索数据,这是我的代码,但我只得到一个空列表。我在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())

但圣殿骑士是空的。在


Tags: 数据代码fromimport列表dbconnectstock
2条回答

不要在列表中提取execute语句,请尝试以下操作:

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

我刚才发现了错误。该目录中的数据库文件为空。我将填充的文件复制到python正在运行的目录中,它可以正常工作。在

相关问题 更多 >