5

Essentially I am trying to calculate a value for a couple of fields after adding them. Below you can see how I am adding the fields and then an example on how my "for" statement is looping through the cursors to add values.

I keep getting an error: "TypeError: sequence size must match size of the row"

I'm not sure what to do about this. Is there a better method than to use the UpdateCursor updateRow statements?

fieldName = ["azVEqSet", "azVERis"]
try:
    arcpy.AddField_management(points, fieldName[0] ,"FLOAT")
    arcpy.AddField_management(points, fieldName[1] ,"FLOAT")
except:
    arcpy.DeleteField_management(points, [fieldName[0], fieldName[1]])
    arcpy.AddField_management(points, fieldName[0] ,"FLOAT")
    arcpy.AddField_management(points, fieldName[1] ,"FLOAT")

cursor = arcpy.da.UpdateCursor(points, ["azVEqSet", "azVERis", "POINT_X", "RASTERVALU", "POINT_Y"])
for row in cursor:
...
     numberInsert = ReturnedVariable
     row[0] = numberInsert
     cursor.updateRow([row])

1 Answer 1

8

Change:

cursor.updateRow([row])

To:

cursor.updateRow(row)

Explanation:

  • row, which you obtained from the arcpy.da.UpdateCursor is a sequence (a tuple, specifically) of a certain length expected by the updateRow method, and by wrapping row in brackets, you are creating a new sequence (a list, specifically) of length 1, which is not the length expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.