import csv
from geopy import geocoders
g = geocoders.Google()
spamReader = csv.reader(open('locations.csv', 'rb'), delimiter='\t', quotechar='|')
for row in spamReader:
a = ', '.join(row)
#print a
place, (lat, lng) = g.geocode(a, exactly_one=False)
print "%s: %.5f, %.5f" % (place, lat, lng)
The data inside locations.csv looks like:
6943 Australia
6944 Australia
6945 Australia
6946 Australia
6947 Australia
6951 Australia
For some reason I am left with a “too many values to unpack” error. The values do print out if I use the commented print statement. Does anyone know why this would be happening?
The problem is the
exactly_oneargument tog.geocode. When I run this in the shell I get:Now, you’re trying to break up that big list into just
place, (lat, lng), when it’s actually a list of those; there aretoo many valuesin that listto unpackinto just the two (placeand(lat, lng)), since there are actually 10. You could do something likeor do some other kind of list manipulation or whatever.