Skip to content Skip to sidebar Skip to footer

Indexerror: List Index Out Of Range - Csv File

There is an error in my code - IndexError: list index out of range, at rates[row[0]] = row[1]: def change(): # read file into dictionary with open('exchangeRate.csv', 'r')

Solution 1:

A simple condition in the for loop may solve the issue.

def change():
    # read file into dictionary
    with open('exchangeRate.csv', 'r') as in_file:
    echRdr = csv.reader(in_file)
    for row in echRdr:
        if len(row) <= 1:
            pass
        else:
            rates[row[0]] = row[1]

Post a Comment for "Indexerror: List Index Out Of Range - Csv File"