Bottom Page

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.
Quote
#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.
Quote
#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.
Quote
#4
That depends on how race_number is set. But it appears to be set in some other code.
Quote
#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.
Quote
#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.
ndc85430 likes this post
Quote
#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.)
ndc85430 likes this post
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

Quote
#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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Still Stumped Milfredo 2 245 Sep-02-2020, 07:48 AM
Last Post: Milfredo
  attribute error stumped on how to fix it. hank4eva 7 398 Aug-11-2020, 04:47 AM
Last Post: hank4eva

Forum Jump:


Users browsing this thread: 1 Guest(s)