TypeError: cannot concatenate 'str' and 'NoneType' objects

Carsten Haese carsten at uniqsys.com
Wed Dec 20 14:39:36 EST 2006


On Wed, 2006-12-20 at 20:22 +0100, Fredrik Lundh wrote:
> thompson.marisa at gmail.com wrote:
> 
> > I'm extremely new to Python and programming as a whole.  I have written
> > a python script with the assistance of ESRI ArcGIS 9.2, which uses
> > Python 2.4.1, however, it gives me this error when I try to run it.
> > I've already posted at ESRI support, and I was hoping that Python
> > people could help me more.
> > 
> > I hope there is something simple I could do to be able to define the
> > object that it thinks is NoneType.
> 
> that would be the None object.
> 
>    http://effbot.org/pyref/None
> 
> which is often used as a placeholder in Python.
> 
> my guess is that it's the next() call that returns None when you've 
> reached the end of the shapefile list; try changing
> 
>      while Townshps !="":
> 
> to
> 
>      while Townshps is not None:
> 
> and see if the problem goes away.

Actually those will both lead to an infinite loop, since you're
comparing the entire list, which is unlikely to ever become "" or None.
You should compare Townshp, not Townshps, to "" or None, whichever
the .next() method actually returns to signal the end of the list.

Then again, I have the sneaking suspicion that you didn't post the
actual code that you're running. The code you posted looks like it
should raise a NameError in the line that says "Townshp =
Townshps.next()".

-Carsten





More information about the Python-list mailing list