Traceback (most recent call last):
File "C:UsersPenguinworkspacegeocode-nojansdatabasesrcgeocode.py", line 15, in
place, (lat, lng) = g.geocode(a)
File "C:Python27libsite-packagesgeopy-0.94.2-py2.7.egggeopygeocodersgoogle.py", line 81, in geocode
return self.geocode_url(url, exactly_one)
File "C:Python27libsite-packagesgeopy-0.94.2-py2.7.egggeopygeocodersgoogle.py", line 88, in geocode_url
return dispatch(page, exactly_one)
File "C:Python27libsite-packagesgeopy-0.94.2-py2.7.egggeopygeocodersgoogle.py", line 111, in parse_xml
"(Found %d.)" % len(places))
ValueError: Didn t find exactly one placemark! (Found 3.)
当 Geopy 遇到一个地址时, 它不喜欢我的应用程序终止 。 我想知道的是, 我怎样才能在 Python 中捕捉例外, 并允许我的程序转到下一个条目 。 源代码如下 :
import csv
from geopy import geocoders
import time
g = geocoders.Google()
spamReader = csv.reader(open( locations.csv , rb ), delimiter= , 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) + "
"
print b
f.write(b)