3
location = geolocator.geocode(" ".join(address.values()))
if location.longitude is not None:
    node['pos'] = [location.longitude, location.latitude]

不明白我仍然收到此错误的方式:

  File "/home/easypc/Documents/Udacity_nano_degree/Data_Wrangling/audit_vilnius.py", line 167, in shape_element
    if location.longitude is not None:
AttributeError: 'NoneType' object has no attribute 'longitude'
4

1 回答 1

9

也就是location变量本身,也None对其进行测试:

if location is not None and location.longitude is not None:

或者更简单地说:

if location:
于 2015-09-24T18:23:25.330 回答