0
我正在使用2個不同的庫並通過它們運行地址。首先我使用geopy來清理和地理編碼地址。然後我通過pygeocoder運行地址來查看輸出是否是有效地址。如果輸出有效,我將地址附加到列表中,我將在稍後返回。如果沒有,我附加「無法清理
」(這是一個燒瓶應用程序)。根據布爾狀態追加到列表中的錯誤
即使地址有效,並且pygeocoder的valid_address函數返回true,由於某種原因,地址也不會被添加到列表中。每次添加「無法清除
」。
這裏是我的代碼:
if g.geocode(address).valid_address:
cleaned.append((str(address) + ", " + str(zipcode.lstrip()) +
", " + str(clean.latitude) + ", " + str(clean.longitude)) + '<br>')
success += 1
else:
cleaned.append('Can not be cleaned <br>')
fail += 1
except AttributeError:
cleaned.append('Can not be cleaned <br>')
fail += 1
except ValueError:
cleaned.append('Can not be cleaned <br>')
fail += 1
except GeocoderTimedOut as e:
cleaned.append('Can not be cleaned <br>')
fail += 1
你是什麼人認爲我做錯了嗎?
這部分代碼看起來不錯。您應該提供[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve) –