我有一个列表,我想将list的所有值传递给Query.I条件,我在Maya脚本编辑器中使用了这个使用maya
码
list = [1,2,3]
db = MySQLdb.connect("host","root","password","test" )
for num in list:
cursor = db.cursor()
cursor.execute('select Name from project WHERE projectID = %s '%(num))
name = cursor.fetchone()
print(name)
cursor.close() 误差
错误: Files\Autodesk\Maya2014\Python\lib\site-packages\MySQLdb\connections.py : ProgrammingError: ProgrammingError:文件C:\Program38-1064#
发布于 2017-12-29 09:02:58
尝试使用没有for循环的cursor.executemany('select Name from project WHERE ProjectID = %s', list)。
这样做对您的性能会更好,因为数据库不会在每个for循环中使用,只使用一次。
同时避免将事物列表、元组等命名。
https://stackoverflow.com/questions/48019927
复制相似问题