在Python中更新记录时出错
我正在尝试用python做一个简单的更新。这是我尝试运行的代码:在Python中更新记录时出错,python,sql,Python,Sql,我正在尝试用python做一个简单的更新。这是我尝试运行的代码: mycursor = mydb.cursor() if(result<5): os.remove(destiny) print(result) print(fi[:-4]) print(lastid) sql = "UPDATE googlesearch SET similarity=%s WHERE tweetid=%d and image
mycursor = mydb.cursor()
if(result<5):
os.remove(destiny)
print(result)
print(fi[:-4])
print(lastid)
sql = "UPDATE googlesearch SET similarity=%s WHERE tweetid=%d and imageName=%s"
value = (str(result),lastid,str(fi[:-4]))
print(value)
mycursor.execute(sql, value)
mydb.commit()
打印值时,我有以下功能:
('2.82258064516129',2636',dimg_10')
在Navicat中使用这句话,一切都很完美。那么,为什么我有这个错误?语句参数位置由
%s
表示,而不是%d
表示
所以我想如果你改变
sql = "UPDATE googlesearch SET similarity=%s WHERE tweetid=%d and imageName=%s"
^
到
您将避免此错误。语句参数位置由
%s
表示,而不是%d
@khelwood这是答案,不是答案comment@pppery是的,我知道。坏习惯。
sql = "UPDATE googlesearch SET similarity=%s WHERE tweetid=%d and imageName=%s"
^
sql = "UPDATE googlesearch SET similarity=%s WHERE tweetid=%s and imageName=%s"
^