Skip to main content
 首页 » 编程设计

python之如何忽略 AttributeError : 'NoneType'

2025年05月04日1652php

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' 

请您参考如下方法:

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

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

或者更简单地说:

if location: