I have a CSV and the following code:
with open("results.csv", 'rt', encoding='UTF-8', errors='ignore') as file:
reader = csv.reader(file, skipinitialspace=True, escapechar='\\')
A = 0
for row in reader:
if row[4] in validclubs and "A" in row[0]:
A = A + 1
print(A)
but it returns:
Traceback (most recent call last):
if row[4] in validclubs and "A" in row[0]:
IndexError: list index out of range.
However if I change my code to:
with open("results.csv", 'rt', encoding='UTF-8', errors='ignore') as file:
reader = csv.reader(file, skipinitialspace=True, escapechar='\\')
A = 0
for row in reader:
if row[4] in validclubs and "A" in row[0]:
print(A)
It will print(A) correctly and return the same error. Therefore, it's not out of range as it prints properly. So what is causing the error?