Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中更新记录时出错_Python_Sql - Fatal编程技术网

在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

我正在尝试用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 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"
                                                            ^