1

I want to update a field in my feature class. I tried to use a da.SearchCursor (code below) but was quickly reminded that tuples are immutable... I ran the code but it failed with a TypeError: 'tuple' object does not support item assignment.

How do I most efficiently retrieve all rows from a feature class and update a field of each row and save it back to the feature class?

with arcpy.da.SearchCursor(fc, fldNames) as sc:
 for thing in sc:
 tmp = 0
 #
 # do stuff here
 #
 thing[idxField] = tmp
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Apr 8, 2015 at 21:12
0

1 Answer 1

8

You want to use an Update Cursor, not a Search Cursor. It allows the same retrieve rows and loop through process, but also enables updating fields.

with arcpy.da.UpdateCursor(fc, fldNames) as uc:
 for thing in uc:
 # assign the data to the various fields
 thing[0] = tmp0
 thing[1] = tmp1
 # trigger an update (save) for that row
 uc.updateRow(thing)
answered Apr 8, 2015 at 21:45
2
  • 1
    you'll need uc.updateRow(thing) instead of cursor Commented Apr 8, 2015 at 21:57
  • Ha, yes. I'm so used to my own syntax ;) Commented Apr 8, 2015 at 22:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.