Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 = conn.cursor()
SerialNum = c.execute('select Serial from BI4000 where Serial in (Select max(Serial) from BI4000)')
print SerialNum
conn.commtt()
conn.close()

the program prints the result

[('00003',)]

which is the last result in the current database, all the data that will be entered into the final database will be serial numbers and so it will be in order.

My question is can I remove all the quotations/brackets/comma as I wish to asign this value to a variable.

The program that I wish to make is a testing system that adds new entries to the database, I wish to check what the last entry is in the database so the system can continue the entries from that point.

like image 828
FuzzyPanda Avatar asked Jul 23 '26 15:07

FuzzyPanda


1 Answers

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]

like image 125
Paris Avatar answered Jul 25 '26 05:07

Paris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!