Hi I have an script that look for information and the information is suppose to be integers, but sometime I find a empty string and because of that I get the following error:
ValueError: invalid literal for int() with base 10: ''
I was trying to do the following, but it does not work.
list = ['12', '14', '45', '']
for i in list:
if '' in i:
i = 0
i
else:
i
This will match everything. It got to be another way and there is no way I can edit the source. Thanks
Don’t use
listas a variable name. Sooner or later you will want to use the builtinglistand get strange bugs 🙂I guess the error you have shown is from elsewhere where you are trying to use
int(i)If
iis supposed to be converted to anint, one way to do it is like thisAnother way is to use an exception handler