我有一个列表,我想将列表的所有值传递给Query的where条件。我在使用maya cmds的Maya Python脚本编辑器中使用它
代码
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()
错误
错误:ProgrammingError:文件C:\ Program Files \ Autodesk \ Maya2014 \ Python \ lib \ site-packages \ MySQLdb \ connections.py第38行:1064#
答案 0 :(得分:0)
尝试使用
没有for循环的cursor.executemany('select Name from project WHERE ProjectID = %s', list)
。
这样做对您的性能会更好,因为数据库不会在每个for循环中使用,只需一次。
还要避免调用事物列表,元组等。