我正在尝试将值列表添加到数据库的表中
QuestionAnswer = [['x','y','z'],['x','y','z']]
(cursor.executemany('INSERT question (QuizID,question,answer) VALUES (%s,%s,%s)',QuestionAnswer)
db.commit()
错误如下:
追溯(最近一次通话):文件“ C:\ Users \ georgia
vost \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ tkinter__init __。py“,
1705行,正在通话中
返回self.func(* args)文件“ C:\ Users \ georgia vost \ Documents \ Private Document \ NEA WORK \ Code
Folder \ appJar \ appjar.py”,第3494行,在
返回lambda * args:funcName(param)文件“ C:\ Users \ georgia vost \ Documents \ Private Document \ NEA WORK \ Code Folder \ prastice程序
1.py“,第37行,按中
cursor.executemany('插入问题(QuizID,问题,答案)值(%s,%s,%s)',QuestionAnswer)文件“ C:\ Users \ georgia
vost \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ site-packages \ mysql \ connector \ cursor.py“,
执行中的第675行
self.execute(操作,参数)文件“ C:\ Users \ georgia vost \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ site-packages \ mysql \ connector \ cursor.py”,
执行中的第557行
psub = _ParamSubstitutor(self._process_params(params))文件“ C:\ Users \ georgia
vost \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ site-packages \ mysql \ connector \ cursor.py“,
_process_params中的第437行
“失败的处理格式参数;%s”%err)mysql.connector.errors.ProgrammingError:处理失败
格式参数; Python“方法”无法转换为MySQL类型
最佳答案
现有代码中可能需要进行许多更改,包括查询语法
cursor.executemany('INSERT INTO question (QuizID,question,answer) VALUES (?,?,?)',list(map(tuple,QuestionAnswer)))