I want to fetch the data in a specific row and be able to perform calculations with it, so far I have this:
import sqlite3 as lite
con=con.connect(mydatabase.db)
cur=con.cursor()
query=cur.execute("SELECT price from items where ID=1")
print(cur.fetchone())
which returns
(13.5,)
I can't make any calculations with that. I decided I would just treat the fetchone() method as a tuple and came up with this:
cur.fetchone()[0]
which returns
13.5
I can work with that, but I think it is a dirty solution is there any other way to fetch the data? I've also tried
for row in cur.fetchall():
print(row[0])
which returns a real number I can work with, but I don't know why this works.
13.5
A number I can work with. I don't know which of the 2 solutions is better, or if there is something more efficient. Could you also give me a brief explanation of the fetch objects I find them somewhat confusing. Thanks your help is greatly appreciated.