我有一个数据库有两列。一个是主键自动增量,另一个是URL的列。第一个被命名为'id',第二个被命名为'longurls'。我跑了下面的代码来检索longurls ='X'值的'id'记录。Sqlite3没有从数据库中读取
import sqlite3
long_url = 'http://www.google.com'
conn = sqlite3.connect('database.db')
c = conn.cursor()
c.execute("SELECT id FROM stuff WHERE longurls=?",(long_url,))
k = c.fetchall()
for stuff in k:
id = stuff[0]
print (id)
This is a picture showing the url exists in database。只有“无”印
另外'打印(“身份证”)'将不打印变量'id',它实际上将打印字符串'“id”':)这可能是一个缩进问题,因为'print'不在for循环中。 – Torxed
对不起,输入Q. – John