import csv
from geopy import geocoders
import time
g = geocoders.GeocoderDotUS()
spamReader = csv.reader(open('locations.csv', 'rb'), delimiter='\t', quotechar='|')
f = open("output.txt",'w')
for row in spamReader:
a = ', '.join(row)
#exactly_one = False
time.sleep(1)
place, (lat, lng) = g.geocode(a)
if None in (lat, lng):
f.write("none")
else:
b = str(place) + "," + "[" + str(lat) + "," + str(lng) + "]" + "\n"
print b
f.write(b)
所以我已经确定,如果 GeocoderDotUS 没有找到地址,它将返回 None。我已经编写了一些脚本来尝试检查 None 但是我似乎仍然得到了这个跟踪。我有点困惑。
Traceback (most recent call last):
File "C:\Users\Penguin\workspace\geocode-nojansdatabase\src\GeocoderDotUS.py", line 17, in <module>
place, (lat, lng) = g.geocode(a)
TypeError: 'NoneType' object is not iterable
我对 None systax 的检查是否有一些错误?提前感谢您的任何帮助....