I'd appreciate if anyone could please tell me if there is a way to go up one row in python cursor. opposite of row = rows.next()
Most cursors don't support iterating backward, but there's an easy way to get the previous row's value, just store a variable:
If you have a need to reset the cursor, many support a reset operation. If you're using ArcGIS, this is
Update: Arash asked how to get values that are even earlier in the dataset. One way would be to store multiple previous rows, extending the logic above. If the dataset is small, another approach would be to store the values already seen in a list of tuples, and index the cursor. The code above does this based on the specific question asked:
What about putting row in the list and iterating backwards?
EDIT: Turns out, that rows object does not work this way :) and row in the list lost reference. But depending on your needs, you may put on the list row.whatever_you_may_need and then iterate backwards. Of course this may work only for SearchCursor and only for some use cases. Also you may check how the rows.next() is iterating over the rows container, if it depends on fetures FID or something else, you may try to revers feature order in FC (also may be option for some caseses).