Byr*_* Mh 2 python database sqlite python-3.x
我要解决的问题是,我想将sqlite3查询结果保存在变量中,我创建了以下代码:
import sqlite3
conn=sqlite3.connect('Database.db')
c=conn.cursor()
#this is implicit, but there is no xxx row in my table, condition and something
#arent real parameters for my query
qry=("SELECT xxx FROM xxx WHERE condition=something")
y=c.execute(qry)
print(y)
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,我得到以下内容:
<sqlite3.Cursor object at 0x01FCD6A0>
Run Code Online (Sandbox Code Playgroud)
现在,例如,如果我使用了for循环在该查询中打印行:
for row in c.execute(qry):
print(row)
Run Code Online (Sandbox Code Playgroud)
我没有问题,但是我想将查询打印的值保存在变量中,应该注意的是,我正在尝试保存具有单行单列的查询,例如: ('EXAMPLE',)
有没有一种方法可以将单行,单列查询保存在变量中,然后打印出来?我应该安装一些模块吗?