gpt4 book ai didi

Python与SQlite交互如何去掉U?

转载 作者:行者123 更新时间:2023-11-30 23:38:23 25 4
gpt4 key购买 nike

晚上,我使用以下代码从数据库中检索数据以便编辑

os.system('cls')
print("Editing the details")
conn = sqlite3.connect('SADS.db')
cur = conn.cursor()
print " "
choice = raw_input("Does the Customer know their user ID? Y/N : ")
if choice == "N":
number = raw_input("What is their phone number? : ")
cur.execute("SELECT * FROM customers")
while True:
rows = cur.fetchone()
if rows == None:
print "No one found with that record"
break
print rows
raw_input("Press Enter to return to the menu")
os.system('cls')

但是当我这样做时,我会返回以下结果:

(u'0001', u'Stack', u'Overflow', u'Confused', u'', u'sqlite', u'PYTH OON', u'07831994131', u'TEST@hotmail.com')

哦,附​​:这些不是真正的细节,我为了安全起见编辑了它们:')

但是无论如何,我如何删除每条数据之前的 u ?

非常感谢。

最佳答案

u 仅表示您有一个 Unicode 字符串,而不是字符串内容的一部分。

u 获得输出,因为您将整个元组打印为元组,而不是单个字符串。

下面的代码工作得很好:

print "Name: %s %s, phone: %s" % (rows[1], rows[2], rows[7])

关于Python与SQlite交互如何去掉U?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14611953/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com