gpt4 book ai didi

python - 列表索引必须是整数而不是 str python sqlite3

转载 作者:行者123 更新时间:2023-12-01 06:05:18 25 4
gpt4 key购买 nike

错误指向的我的代码如下所示

for i in array1:
cursor.execute("insert into Recipe values (?,?,?)",(array1[i], array2[i], array3[i]))
db.commit()

数组的内容是字符串,那么如何将数组放入sqlite3表中?

最佳答案

使用zip()一起迭代所有三个数组:

for row in zip(array1, array2, array3):
cursor.execute("insert into Recipe values (?,?,?)", row)
db.commit()

关于python - 列表索引必须是整数而不是 str python sqlite3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8283536/

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