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)
Solved! Go to Solution.
At a minimum, you are missing a comma after the first argument in your SearchCursor. Try fixing that first.
It looks like you posted a partial Traceback, can you share the whole thing? Does Line 1 in your code snippet line up with Line 1 in the error message? I am guessing not because setting a variable to zero would not generate a TypeError.
That was what was in the Python window in Pro.
Normally when I used cursors, row[0] is not an issue
and it works in this:
PLOCU_set= set(r[0].replace(" ", "") for r in arcpy.da.SearchCursor(fc, ["PLOCU_"]) if not r[0] is None)
also, lines 4 and 5 are not indented properly
I tried to make it look better from what was pasted in from Pro. The code runs fine in a jupytr notebook.
fc = "AddressPtsFormatted"
address_sum = 0
with arcpy.da.SearchCursor('AddressPtsFormatted' ["PLOC_"]) as cursor:
for r in cursor:
number = r[0]
address_sum += number
Traceback (most recent call last):
File "<string>", line 3, in <module>
TypeError: string indices must be integers
This is what I ran. I cant edit the first post. And I just learned that it helps to set the language before you past code
At a minimum, you are missing a comma after the first argument in your SearchCursor. Try fixing that first.
ohhhhhhhhhhhh thats it i bet
I cant edit the first post.
Look for the edit button at upper right (you can't edit in a dropdown but you can edit by clicking up there).
Not that it matters that much: new Geonet platform soon!