设为首页 - 加入收藏 华夏网 (http://www.hxwgxz.com)- 云主机,资讯,互联网,人工智能,云计算,大数据,区块链,VR,站长网!
热搜: 2019 google 中国 2020
当前位置: 主页 > 编程 > 正文

python-TypeError:execute()需要2到3个位置参数,但是给出了7个

发布时间:2021-02-27 05:43 所属栏目:[编程] 来源:网络整理
导读:我有以下代码,并抛出TypeError:execute()接受2到3个位置参数,但给出了7个.我不确定是否正确,但是这里是: result_time = cur.execute("SELECT appointment_id FROM appointments WHERE appointment_time =%s",[appointment_time],"AND appointment_date =%s

我有以下代码,并抛出TypeError:execute()接受2到3个位置参数,但给出了7个.我不确定是否正确,但是这里是:

result_time = cur.execute("SELECT appointment_id FROM appointments WHERE appointment_time =%s",[appointment_time],"AND appointment_date =%s",[appointment_date],"AND doctor_id =%s",[actual_doctor_id.get('doctor_id')])

因此,当满足所有要求时,我想要一个特定的约会ID. 最佳答案 cursor.execute接受sql和一个参数元组-您单次给这些参数-因此您“塞满了”它并得到

TypeError: execute() takes from 2 to 3 positional arguments but 7 were given

更改您的代码包含1个sql语句和一个带params的元组:

result_time = cur.execute(
    "SELECT appointment_id FROM appointments WHERE appointment_time = %s AND appointment_date = %s AND doctor_id = %s",( appointment_time,appointment_date,actual_doctor_id.get('doctor_id')) )          

它会工作.

 cursor.execute( slq,( param1,param2,... ) )
 #                      this is all a tuple - hence the 2nd allowed param to execute.

见f.e. myslq-documentation或使用http://bobby-tables.com/python作为快速参考.

【免责声明】本站内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

网友评论
推荐文章