Select to view content in your preferred language

Strange errors in Pro's Python window with search cursor

1415
11
Jump to solution
07-17-2020 03:30 PM
DanDeegan
New Contributor III
address_sum = 0
with arcpy.da.SearchCursor('AddressPtsFormatted' ["PLOC_"]) as cursor:
   for r in cursor:
   number = r[0]
   address_sum += number‍‍‍‍

returns the error: 

Traceback (most recent call last):File "<string>", line 1, in <module> TypeError: string indices must be integers‍‍‍‍‍‍‍

The code runs in jupytr notebook

(no, i wasn't adding up every address in my area because I am loopy on Friday afternoon, why would anyone find the sum of addresses)

0 Kudos
11 Replies
by Anonymous User
Not applicable

You might check the value type which script returns, it looks like the type is string rather than integer.

0 Kudos
jefryarch
New Contributor

TypeError: means that you are trying to perform an operation on a value whose type is not compatible with that operation. An Iterable is a collection of elements that can be accessed sequentially . In Python, iterable objects are indexed using numbers . When you try to access an iterable object using a string or a float as the index, an error will be returned as TypeError: string indices must be integers. This means that when you're accessing an iterable object like a string or float value, you must do it using an integer value.

 

0 Kudos