gpt4 book ai didi

python - 如何在Python中将二维数组添加到数据库中

转载 作者:行者123 更新时间:2023-11-29 16:12:13 25 4
gpt4 key购买 nike

我正在尝试将值列表添加到数据库的表中

QuestionAnswer = [['x','y','z'],['x','y','z']]

(cursor.executemany('INSERT question (QuizID,question,answer) VALUES (%s,%s,%s)',QuestionAnswer)

db.commit()

错误如下:

Traceback (most recent call last): File "C:\Users\georgia vost\AppData\Local\Programs\Python\Python37-32\lib\tkinter__init__.py", line 1705, in call return self.func(*args) File "C:\Users\georgia vost\Documents\Private Document\NEA WORK\Code Folder\appJar\appjar.py", line 3494, in return lambda *args: funcName(param) File "C:\Users\georgia vost\Documents\Private Document\NEA WORK\Code Folder\prastice program 1.py", line 37, in press cursor.executemany('INSERT question (QuizID,question,answer) VALUES (%s,%s,%s)',QuestionAnswer) File "C:\Users\georgia vost\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\cursor.py", line 675, in executemany self.execute(operation, params) File "C:\Users\georgia vost\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\cursor.py", line 557, in execute psub = _ParamSubstitutor(self._process_params(params)) File "C:\Users\georgia vost\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\cursor.py", line 437, in _process_params "Failed processing format-parameters; %s" % err) mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python 'method' cannot be converted to a MySQL type

最佳答案

现有代码可能需要进行许多更改,包括查询语法

cursor.executemany('INSERT INTO question (QuizID,question,answer) VALUES (?,?,?)',list(map(tuple,QuestionAnswer)))

关于python - 如何在Python中将二维数组添加到数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55165377/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com