Skip to content Skip to sidebar Skip to footer

Sqlite3 Remove Brackets From Printed Data

I have created a script that finds the last value in the first row of my database import sqlite3 global SerialNum conn = sqlite3.connect('MyFirstDB.db') conn.text_factory = str c =

Solution 1:

The result of the query you execute is being represented as a Python list of Python tuples.

The tuples contained in the list represent the rows returned by your query.

Each value contained in a tuple represents the corresponding field, of that specific row, in the order you selected it (in your case you selected just one field, so each tuple has only one value).

Long story short: your_variable = SerialNum[0][0]

Solution 2:

If you want to retrieve just one column from one row, use:

c.execute('select Serial from BI4000 where Serial in (Select max(Serial) from BI4000)')
result= c.fetchone()
if result:  # firstrow returned?
    print result[0]  # firstcolumn

Your query could be simplified to:

c.execute('Select max(Serial) from BI4000')

Post a Comment for "Sqlite3 Remove Brackets From Printed Data"