我正在尝试将值列表添加到数据库的表中
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类型
答案 0 :(得分:0)
您现有的代码中可能需要进行许多更改,包括查询语法
cursor.executemany('INSERT INTO question (QuizID,question,answer) VALUES (?,?,?)',list(map(tuple,QuestionAnswer)))