GeocoderDotUS Geopy('NoneType'对象不可迭代)

时间:2012-05-29 23:32:14

标签: python exception geopy

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行,in     place,(lat,lng)= g.geocode(a) TypeError:'NoneType'对象不可迭代

我检查过以确保在放置地理编码(a)之前有一个值。也许没找到比赛?如果是这种情况,我想我只需添加一个if not b then语句。有谁知道更多关于这个?

我看到添加

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

产量: 178连接路波莫纳QLD

1 个答案:

答案 0 :(得分: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

你的猜测是正确的。打开包装前检查。