Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Really stumped now
#1
I thought I had fixed my problem. In fact I marked post solved. The following code works as long as user selects Race 1. But select any other race number and it won't print out. Throws the following error.

def load_track_to_Handi():
	my_tracklabel= Label(root, text ="                                                                               ", fg= "#F50808", font = ("sans_serif" , 16)).place(x=380, y=430)
	read_csvfile_into_array()
	
		
	global track_abrev
	global race_number
	global xx
	
	#if fileFound ==True:

		
		 
	
	
	hcount = 0
	
	with open( 'C://guis/f_racefiles/'+ track_abrev + '.csv' , 'r') as race_file:

		
		df = pd.read_csv(race_file, header =None)
		
		xx = df.iloc[ :,0:19 ].values
		
		

		for i in range(0,len(xx)):
			if int(xx[hcount][1])== int(race_number):
			 
				print(xx[hcount][18])					
				hcount+=1	
Select race 1 and this is the print out:
TICKET TO RICHES
FLASHY PATCH
HAUTE PROSPECT
MISS VICKI
HONEST GINGER
ABOGADA
But if any other race number selected it throws this error:

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 134, in select_track
load_track_to_Handi()
File "testloop.py", line 95, in load_track_to_Handi
if int(xx[hcount][0])== int(race_number):
ValueError: invalid literal for int() with base 10: 'AP '


I don't understand this at all. I thought the [1] in the code stood for column 1.
Reply
#2
It looks like race_number is set to "AP". When passed to int(), python can't convert it to a number, so the error is thrown.
Reply
#3
When I click the button that represents race 1 it works fine. Click any other button, say race 2 or race 3 or race 4 and the error gets thrown. I don't understand why.
Reply
#4
That depends on how race_number is set. But it appears to be set in some other code.
Reply
#5
It is. But I make sure both are set to integers in my code in the conditional statement. I can not find anywhere that addresses this issue. That's why I need some help. I have looked everywhere and watched a bunch of videos. If race 1 works, then the other race numbers should work since they are all coded the same.
Reply
#6
Put in some debugging statements. Everywhere race_number is assigned, put in a logging statement that says "I'm setting race_number to {race_number}". Or some that check periodically what it's set to.

Then narrow down to the section that is setting it.
Reply
#7
(Sep-17-2020, 12:33 AM)Milfredo Wrote: It is. But I make sure both are set to integers in my code in the conditional statement. I can not find anywhere that addresses this issue. That's why I need some help. I have looked everywhere and watched a bunch of videos. If race 1 works, then the other race numbers should work since they are all coded the same.
you cannot argue with the interpreter. provide a sample csv file, so that we are able to reproduce the error. edit your code to be minimal reproducible example (i.e. no GUI, no user input, etc.)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
Thank you guys for the help. I figured out the solution. I changed the value of race number to an integer at time button clicked and passed it as an Integer. Converted the file number from string value to integer in the conditional if statement. Thanks again for all the help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Stumped by my own code (ratio & epoch-time calculation). MvGulik 2 2,090 Dec-30-2020, 12:04 AM
Last Post: MvGulik
  Still Stumped Milfredo 2 2,057 Sep-02-2020, 07:48 AM
Last Post: Milfredo
  attribute error stumped on how to fix it. hank4eva 7 4,597 Aug-11-2020, 04:47 AM
Last Post: hank4eva

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020