4

我正在尝试使用此代码从 sqlite 数据库列中读取所有温度值,但输出显示[(u'29',), (u'29',), (u'29',)]并且我仅将数值存储在数据库中。我希望输出是[29, 29, 29]

import sqlite3

conn = sqlite3.connect("growll.db")
cursor = conn.cursor()

print "\nHere's a listing of all the records in the table:\n"
cursor.execute("select lchar from GrowLLDados")

print cursor.fetchall() 
4

2 回答 2

6

尝试这个:

import sqlite3

conn = sqlite3.connect("growll.db")
cursor = conn.cursor()

print "\nHere's a listing of all the records in the table:\n"
cursor.execute("select lchar from GrowLLDados")    

print [int(record[0]) for record in cursor.fetchall()]
于 2012-12-26T23:03:44.227 回答
1

print [int(i[0]) for i in cursor.fetchall()]

让我知道你是怎么办的。

于 2012-12-26T23:00:17.543 回答