我是python新手,甚至是sql新手,但我整个上午都在努力让它工作,我似乎都搞不懂。我有一个名为POSTS(id)的表设置。我试图检查id列中是否已经有一个数字,但是postid是什么并不重要,因为即使postid设置为数据库中没有的数字,数据也不会返回none。
import sqlite3 as lite
import sys
con = lite.connect('post.db')
postid = '52642'
cur = con.cursor()
cur.execute("select id from POSTS where id=?", (postid,))
data = cur.fetchall()
if data is None:
print ('not found')
else:
print ('found')
声明
将为
data
分配一个空列表,不None
,当没有找到任何内容时。所以把支票换成:
而不是:
相关问题 更多 >
编程相关推荐