I'm trying to read a csv file, using the separator ',' but when I do line [1] I have an indexing error: I go out of range. For what reason?
what follows is a part of the code that manages the split but does not work.
with open(fileLocation, newline='') as fileCsv:
reader = csv.reader(fileCsv, delimiter=',')
first = True
second = False
prev = fileCsv.readline()
reader= list(reader)
for line in reader:
if first:
first = False
second = True
continue
email = line[20].lower()
nameSurname = line[0]
msg=''
if nameSurname == "" and email == "":
return render_template('LoadCSV.html', login=loginStr(), avviso='err'+msg, fileLocation=fileLocation, category=app.category)
data = line[3][0:10].replace("/","-")
group = line[1]
startingTime = line[16][11:]
EndingTime = line[3][11:]
language = line[10]
This instead is an example of the data contained in the file:
Name Surname,Student,"Assessment timed out","2019/10/31
12:10:08",19,72,26,Fail,000000000,000000000000000,"English
B1",Stefano,"2019/10/29
08:45:15",IDNUMBER,10.30.6.5,157.27.1.13,"2019/10/31
11:24:56",2706,,,[email protected],,,,,,,,,"English B1"
Name2 Surname2,Student,"Assessment timed out","2019/10/31
12:10:08",19,72,26,Fail,000000000,000000000000000,"Enghlish
B1",Stefano,"2019/10/29
08:45:15",IDNUMBER,10.30.6.5,157.27.1.13,"2019/10/31
11:24:56",2706,,,[email protected],,,,,,,,,"English B1"
question from:
https://stackoverflow.com/questions/65644718/read-a-csv-file-containing-data-separated-by-a-delimiter-in-python-flask