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)

I can't really determine why I am receiving

Traceback (most recent call last): File "C:\Users\Penguin\workspace\geocode-nojansdatabase\src\yahoo.py", line 17, in place, (lat, lng) = g.geocode(a) TypeError: 'NoneType' object is not iterable

I checked to make sure there was a value in a before the geocode(a) call was placed. Perhaps a match was not found? If that is the case the I guess I just have to add in an if not b then statement. Does anyone know more about this?

I am seeing that adding a

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

Does yield: 178 Connection Rd Pomona QLD

Eae
  • 4,191
  • 15
  • 55
  • 92
  • 1
    A copy of the full traceback/error will help pinpoint the error location, can you add this to your question. – Levon May 29 '12 at 23:33
  • `spamReader` is apparently not iterable, meaning there are no rows to loop over. Are you certain that `locations.csv` is in the same directory as your script? – Junuxx May 29 '12 at 23:36
  • Yes. I am in the eclipse environment and it does say that locations.csv is in there. – Eae May 30 '12 at 07:46
  • The first entry in locations.csv is 178 Connection Rd Pomona QLD – Eae May 30 '12 at 07:47
  • a then contains that value 178 Connection Rd... – Eae May 30 '12 at 07:47
  • If a has a value and I see it in the debugger then the for loop was entered at least one time... No? – Eae May 30 '12 at 07:49
  • So I see you are asking for the whole traceback Traceback (most recent call last): File "C:\Users\Penguin\workspace\geocode-nojansdatabase\src\yahoo.py", line 17, in place, (lat, lng) = g.geocode(a) TypeError: 'NoneType' object is not iterable – Eae May 30 '12 at 07:58
  • I have tried turning on additional exception handling which is still yielding the same exception to come out – Eae May 30 '12 at 08:20

1 Answers1

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

Your guess is correct. Check before unpacking.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358