简体   繁体   中英

why do I recieve “ValueError: invalid literal for int() with base 10: ''” when I do insert integer

This is my function:

def _make_junction(i_str, lat_str, lon_str, *link_row):

'This function is for local use only'

print(i_str + ' ' + lat_str + ' ' + lon_str)

i, lat, lon = int(i_str), float(lat_str), float(lon_str)

. . .

However, I receive:

0 29.4412461 34.841524

1 29.44148 34.8417302

2 29.442425 34.8422023

3 29.444021 34.8432352

4 29.4476115 34.8460974

5 29.4529769 34.8508125

6 29.454155 34.8518639

7 29.4542612 34.8519374

8 29.492126 34.8987881

9 29.4920116 34.8990719

10 29.4912583 34.9004446

Error message:

Traceback (most recent call last):
File "C:\Users\Eli\Documents\Introduction to AI\HW1\stats.py", line 40, in <module>
print_stats()
 File "C:\Users\Eli\Documents\Introduction to AI\HW1\stats.py", line 33, in print_stats
for k, v in map_statistics(load_map_from_csv()).items():
 File "C:\Users\Eli\Documents\Introduction to AI\HW1\ways\tools.py", line 134, in wrap
res = f(*x, **d)
 File "C:\Users\Eli\Documents\Introduction to AI\HW1\ways\graph.py", line 112, in load_map_from_csv
lst = {int(row[0]):_make_junction(*row) for row in csv.reader(it)}
 File "C:\Users\Eli\Documents\Introduction to AI\HW1\ways\graph.py", line 112, in <dictcomp>
lst = {int(row[0]):_make_junction(*row) for row in csv.reader(it)}
 File "C:\Users\Eli\Documents\Introduction to AI\HW1\ways\graph.py", line 91, in _make_junction
i, lat, lon = int(i_str), float(lat_str), float(lon_str)
ValueError: invalid literal for int() with base 10: ''

Why is this happening? the value of i_str is integer...

Thanks in advance.

The last line in the traceback implies that i_str is an empty string.

invalid literal for int() with base 10: ''

Check your CSV, I'll bet your parsing is encountering a corner case where that data isn't formatted as you would expect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM