I have a csv file with a 1st part made up of 3 entries and 2nd part made up of 2 entries. I want to isolate the data made up of 3 entries.
i wrote the following:
filename=open("datafile.txt","r")
data_3_entries_list=[]
for line in filename:
fields=line.split(",")
if fields[2] == 0:
break
else:
data_3_entries_list.extend(line)
i get the error message:
if fields[2] == 0 :
IndexError: list index out of range
print(data_3_entries_list)
I also tried with if fields[2] is None but i get the same error. I dont understand why im getting this error?
if len(fields) >= 30based