[Solved] Python – index out of range error [duplicate]


Some of your lines in scores.txt don’t have a comma. You can check for those :

if len(x) == 1 : #there is no comma
    continue #ignore line and go to the next one

This code would ignore the lines without a comma. Place it just after computing x = line.split(‘,’) .

Same if you just want to skip empty lines :

if line.strip() == '': #remove whitespace then check if line is empty
    continue

0

solved Python – index out of range error [duplicate]