在Python中将SQLite 3数据存储为变量
我是否可以将存储在sqlite3表中的数据用作Python变量?我正在寻找与此伪代码类似的东西:在Python中将SQLite 3数据存储为变量,python,sql,python-2.7,sqlite,Python,Sql,Python 2.7,Sqlite,我是否可以将存储在sqlite3表中的数据用作Python变量?我正在寻找与此伪代码类似的东西: import sqlite3 conn = sqlite3.connect(DATABASE) cursor = conn.cursor() variable = cursor.execute("fetch data from table") 要从表中读取单个值,请使用一个SELECT查询,该查询返回一个包含单行和单列的结果: for row in cursor.execute("SELECT M
import sqlite3
conn = sqlite3.connect(DATABASE)
cursor = conn.cursor()
variable = cursor.execute("fetch data from table")
要从表中读取单个值,请使用一个SELECT查询,该查询返回一个包含单行和单列的结果:
for row in cursor.execute("SELECT MyColumn FROM MyTable WHERE ID = ?", [123]):
variable = row[0]
break
else:
variable = 0 # not found
为什么你不能只做一个选择?@CL。我想从表中选取一个特定的列