2024-05-17 10:18:56 发布
网友
这是我的数据:
mylist=["happy" , "sad", "cute"] country = 'US'
我的桌子
在python中,我的sql查询如下所示:
myquery= """select * from mytable where country = '%s' and terms is in ('%s', '%s');""" %(country, tuple(mylist))
错误:格式字符串的参数不足。在
python的db adapter提供了参数格式,您只需使用它:
cursor.execute('select * from mytable where terms in %s and country = %s;', (tuple(mylist), country))
查看更多:https://www.python.org/dev/peps/pep-0249/#id14
python的db adapter提供了参数格式,您只需使用它:
查看更多:https://www.python.org/dev/peps/pep-0249/#id14
相关问题 更多 >
编程相关推荐