简体   繁体   中英

Index Error in python, list index out of range

I use this script to manipulate a csv and upload it to database, this have been used multiple times with no problem. Today I was running it but got this list index out of range which does not make any sense to me. The script have the following commands:

csv_reader=csv.DictReader(csv_file,dialect='excel-tab')
        data=[row for row in csv_reader]
        fieldnamesreader = [I for I in data[0].keys()]

This last line is where it gave me the error:

 File "MyScript.py", line 108, in main
    fieldnamesreader = [I for I in data[0].keys()]
IndexError: list index out of range

I'm using python 2.7

您的 CSV 文件为空,因此数据成为空列表。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM