0

I am trying to update a field in a database, row by row, with a list of values. The following script works fine, but I can't help thinking there might be a more efficient (or pretty) way to update rows with items from a list. Here, I've just set a counter and updated the rows with the changing index item of the list.

listAreas = [1234.45, 3456.67, 6547.87, 536.76, 34.10]

indexIncr = 0
with arcpy.da.UpdateCursor(databasePath, "ColumnName") as cursorArea:
    for rowArea in cursorArea:
        rowArea[0] = listAreas[indexIncr]
        cursorArea.updateRow(rowArea)
        indexIncr+=1

1 Answer 1

1

I don't know if it is more pretty, but this seems more pythonic to me.

for indexIncr, rowArea in enumerate(cursorArea):
    rowArea[0] = listAreas[indexIncr]
    cursorArea.updateRow(rowArea)
Sign up to request clarification or add additional context in comments.

1 Comment

I knew I was looking for something just a little more simple and creative. I use enumerate all the time but today, my brain totally forgot about it. thanks for the suggestion. Nice one :)

Your Answer

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.