Sep-11-2020, 06:12 AM
This is really strange. The following function gets called, and throws an error and then immediately prints out part of what I want. I don't understand.
def load_track_to_Handi(): global track_abrev global race_number with open('C://guis/f_racefiles/'+ track_abrev + '.csv', 'r') as track_file: csv_reader = csv.reader(track_file) for line in csv_reader: if race_number in line[1]: print(line )Error message:
Error:Milford@LAPTOP-3NUEM60C MINGW64 /c/guis
$ python testloop.py
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Milford\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "testloop.py", line 79, in select_track
load_track_to_Handi()
File "testloop.py", line 55, in load_track_to_Handi
if race_number in line[1]:
IndexError: list index out of range
['AP ', '1', 'D', 'C', '13000', '18', '2', '107', '17', '9', '1', '82', '8', '79', '6', '323', '42', '3', 'EYE ON THE FINISH', '17', '0', '0', '3', '0', '5', '0', '1', '0', '2020', '9', '2019', '6', '15', '1', '14', '65', '1320', '1540', '1870', '1800', '1870', '1430', '1540', '1320', '1870', '1800', 'D', 'D', 'T', 'D', 'T', 'D', '1540', 'D', 'T', 'D', '7', '11', '10', '7', '10', '8', '7', '10', '10', '6', '7', '6', '5', '1', '2', '8', '2', '6', '4', '5', '7', '6', '4', '1', '3', '8', '1', '6', '3', '6', '4', '65', '55', '65', '65', '65', '65', '48', '0', 'FOR FILLIES AND MARES THREE YEARS OLD AND UPWARD WHICH HAVE NEVER WON TWO RACES. Three Year Olds; 121 lbs.; Older; 124 lbs. Non-winners Of A Race Since July 13 Allowed 3 lbs. Claiming Price $10;000 (Races Where Entered For $8;000 Or Less Not Considered In Allowances).', 'Clm 10000']
It prints the first line from the file but stops there. Should be another 5 lines printed out based on contents of the file I am accessing. I can't find this problem described anywhere.