python sqlite fetchall没有返回正确的数据类型
问题描述:
我有一个问题,让fetchall返回正确的数据类型。 fetchone确实有用?!?!python sqlite fetchall没有返回正确的数据类型
con = sqlite3.connect('test.db', detect_types=sqlite3.PARSE_DECLTYPES)
与CON:
cur = con.cursor()
cur.execute("SELECT df1 FROM PLCValues")
rows = cur.fetchall()
#print(rows)
for row in rows:
print (row)
print(row)
返回
================= RESTART: C:/Users/zippo/Desktop/Graphit.py =================
(44.64769744873047,)
(44.691650390625,)
(44.691650390625,)
(44.471900939941406,)
(44.64769744873047,)
FETCHONE
con = sqlite3.connect('test.db', detect_types=sqlite3.PARSE_DECLTYPES)
与CON:
cur = con.cursor()
cur.execute("SELECT df1 FROM PLCValues")
rows = cur.fetchone()
#print(rows)
for row in rows:
print (row)
print(row)
返回:
================= RESTART: C:/Users/zippo/Desktop/Graphit.py =================
44.64769744873047
44.64769744873047
答
cur.fetchall()
返回一个元组的元组。据https://docs.python.org/2/library/sqlite3.html它似乎正在返回正确的类型。你可能想遍历单个元组来获得单个元素。
“PLCValues”表中“df1”列的类型是什么? –