gpt4 book ai didi

python - 在mysql数据库的单个单元格中插入python字典

转载 作者:行者123 更新时间:2023-11-29 23:57:18 26 4
gpt4 key购买 nike

我有这本Python字典。我正在尝试将其插入 mysql 数据库中。因此,我使用 json.dumps 将其转换为 json,但仍然收到错误,即在字符串格式化期间并非所有参数都已转换。应该做什么?

{'point': '+', 'time': '00:02', 'acceptedSubmissionId': 42, 'title': 'GNU C++'}

我的代码:cursor.execute("insert into tablename A value %s", json.dumps(user['scoreCard'][i]))

编辑:我将 json 放在方括号中,以创建一个元组,并且它有效。它是否正确??cursor.execute("插入竞赛_"+str(id)+"("+str(unichr(i + 65))+") 值 (%s)", [json.dumps(user['scoreCard] '][i])])

最佳答案

改用这个:

cursor.execute("insert into tablename A value {0}", json.dumps(user['scoreCard'][i]))

符号 %s 将很快被弃用。

关于python - 在mysql数据库的单个单元格中插入python字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25248885/

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