当前位置:首页 > 数据库 > SQlite

如何使fetch方法返回INTEGER列的int值而不是字符串Python sqlite?

我想使用此代码从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() 

解决方法:

试试这个:

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()]

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!