Is it possible to sort an arcpy.da.UpdateCursor()?
The sort completely exhausts the cursor before you go into updateRow
. The way that cursors work is that the updateRow
call doesn't work on arbitrary rows out-of-seqence, but on the current one being iterated over. That is, you can only operate on one row at a time.
You may want to look into doing this on the geodatabase side instead. You can specify an ORDER BY
clause and sort it before you get to it instead.
As @nmpeterson pointed out, you can input an sql clause into the cursor call to sort by a field:
UpdateCursor (in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points}, {sql_clause})
SQL prefix supports None, DISTINCT, and TOP. SQL postfix supports None, ORDER BY, and GROUP BY.
sql_clause=(None, 'ORDER BY SORT_FIELD ASC') -- or DESC
info comes from the ESRI help: http://resources.arcgis.com/en/help/main/10.2/index.html#//018w00000014000000