sqlite3从打印数据中删除括号 [英] sqlite3 remove brackets from printed data

查看:95
本文介绍了sqlite3从打印数据中删除括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个脚本,该脚本在数据库的第一行中找到最后一个值

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

程序将打印结果

[('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.

推荐答案

您执行的查询结果被表示为Python的Python列表元组。

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).

长话短说 your_variable = SerialNum [0] [0]

这篇关于sqlite3从打印数据中删除括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆