How to get fetch methods to return int values ​​for INTEGER columns instead of Python sqlite rows?

I try to use this code to read all temperature values ​​from a sqlite database column, but the output shows [(u'29',), (u'29',), (u'29',)] , and I only save numeric value in the database. I would like the result to be [29, 29, 29]

 import sqlite3 conn = sqlite3.connect("growll.db") cursor = conn.cursor() print "\nHere a listing of all the records in the table:\n" cursor.execute("select lchar from GrowLLDados") print cursor.fetchall() 
+4
source share
2 answers

Try the following:

 import sqlite3 conn = sqlite3.connect("growll.db") cursor = conn.cursor() print "\nHere 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()] 
+6
source

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

Let me know how you are doing.

+1
source

All Articles