【问题标题】:how to ignore AttributeError: 'NoneType'如何忽略 AttributeError:'NoneType'
【发布时间】:2015-12-22 11:13:55
【问题描述】:
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'

【问题讨论】:

标签: python attributeerror nonetype geopy


【解决方案1】:

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

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

或者更简单地说:

if location:

【讨论】:

    猜你喜欢
    • 2021-10-28
    • 1970-01-01
    • 2022-01-15
    • 2014-04-08
    • 1970-01-01
    • 2021-04-06
    • 1970-01-01
    • 2014-11-29
    • 1970-01-01
    相关资源
    最近更新 更多