这是我的功能:
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)
。 。
但是,我收到了:
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
错误讯息:
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: ''
为什么会这样? i_str 的值是整数...
提前致谢。
答案 0 :(得分:1)
回溯中的最后一行表示i_str
是一个空字符串。
invalid literal for int() with base 10: ''
检查你的CSV,我打赌你的解析遇到了一个角落的情况,那里的数据没有像你期望的那样格式化。