Invalid literal for int() with base 10.

4128
4
Jump to solution
07-23-2013 02:51 PM
ScottBarron
New Contributor III
Hi, I keep getting this error message:
Traceback (most recent call last):   File "C:\Users\sbarron\Desktop\AIDA_Tool\AutoInfastructureMask.py", line 123, in <module>     Max= int(max(Quakesim_List)) ValueError: invalid literal for int() with base 10: '999.332202045'


And I have no idea why. This code has worked on bigger numbers than this one, so I'm completely stumped. Any help would be appreciated.
-Scott
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RhettZufelt
MVP Frequent Contributor
It appears that maybe your list contains strings  '999.332202045'

Try this, might work for you, will make sure if string, converts to float, then int:

 Max= int(float(max(Quakesim_List)))  

View solution in original post

0 Kudos
4 Replies
ScottBarron
New Contributor III
Oh and for reference, the list in the code is just a list full of floating point numbers.
0 Kudos
RhettZufelt
MVP Frequent Contributor
It appears that maybe your list contains strings  '999.332202045'

Try this, might work for you, will make sure if string, converts to float, then int:

 Max= int(float(max(Quakesim_List)))  
0 Kudos
JasonScheirer
Occasional Contributor III
Your variables in Quakesim_List are strings, hence the failure.

int(max(float(sim) for sim in Quakesim_List))

Do that.
0 Kudos
ScottBarron
New Contributor III
Apparently it was a case of bad data. I tried with the float inserted into the code and it worked but it gave me a messed up output. I regenerated the data and it worked just fine. Thanks for your help!