I just can't understand why my list is out of range.
I've been stuck on this problem forever now and can't wrap my head around what the problem might be.
Obviously I'm new into programming.
def list(self,filename):
with open(filename, "r") as listTeams:
teamCount = 0
indexList = []
unsortedList = []
lines = listTeams.readlines()
for line in open(filename):
teamCount += 1
listTeams.seek(0)
for i in range(0, teamCount):
tempStr = listTeams.readlines(i)
tempStr = "".join(tempStr)
indexList = tempStr.split(" ")
for i in range(0,i):
print(i)
unsortedList[i] = Team(indexList[0], indexList[1], indexList[2], indexList[3], indexList[4], indexList[5], indexList[6])
print(unsortedList[i])
return
I get this error message:
unsortedList[i] = Team(indexList[0], indexList[1], indexList[2], indexList[3], indexList[4], indexList[5], indexList[6])
IndexError: list index out of range
indexList[6]requires every line to have at least 7 fields.list, since that is a built-in function in python.listTeams.readlines(i)to read each line? You already read them all into the listlines. You can just dofor tempStr in lines.teamCount = len(lines), you don't need to read the file again and count the lines.