0
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)


b = str(place) + "," + "[" + str(lat) + "," + str(lng) + "]" + "\n"
print b
f.write(b)

我无法确定我收到的原因

Traceback(最近一次调用最后一次):文件“C:\Users\Penguin\workspace\geocode-nojansdatabase\src\yahoo.py”,第 17 行,(lat, lng) = g.geocode(a) TypeError: “NoneType”对象不可迭代

在进行 geocode(a) 调用之前,我检查以确保 a 中有一个值。也许没有找到匹配项?如果是这种情况,我想我只需要添加一个 if not b then 语句。有人知道更多吗?

我看到添加一个

a = ', '.join(row)
print(a)

是否产生:178 Connection Rd Pomona QLD

4

1 回答 1

1
>>> a, (b, c) = None
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not iterable
>>> a, (b, c) = ('foo', None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not iterable

你的猜测是正确的。开箱前检查。

于 2012-05-30T08:21:28.897 回答