首页 > 解决方案 > Mysqldb:IndexError:列表索引超出范围

问题描述

运行以下代码以将 csv 导入 mysql 数据库时,出现错误:

IndexError: list index out of range

我知道我有 12 列和 12 个值,那么错误来自哪里?

csv_data = csv.reader('demofile3.csv')
for row in csv_data:
    cursor.execute("INSERT INTO producten(offerId, ean, conditionName, conditionCategory, conditionComment, bundlePricesPrice, fulfilmentDeliveryCode, stockAmount, onHoldByRetailer, fulfilmentType, mutationDateTime, referenceCode) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[11]))

CSV 文件内容(前 2 行,共 47 行):

offerId,ean,conditionName,conditionCategory,conditionComment,bundlePricesPrice,fulfilmentDeliveryCode,stockAmount,onHoldByRetailer,fulfilmentType,mutationDateTime,referenceCode
02822cf7-d29e-4f94-a3f3-29a22007ab16,0655160828881,NEW,NEW,,11.95,24uurs-12,0,false,FBR,2020-11-10 16:51:43.329 UTC,

标签: pythonmysqlpython-3.xmysql-python

解决方案


推荐阅读