Counting in for-loop using ArcPy Cursor?

In theory (because I don't know arcpy), simply use the standard function enumerate (GeoNet: Enumeration of a cursor)

for i, row in enumerate(cur):
     row[0] = i
     cur.updateRow(row)

The easiest option would be to reference the OID in the attributes using the OID@ token in a SearchCursor.

import arcpy

shp = r'X:\path\to\your\shapefile.shp'

with arcpy.da.SearchCursor(shp, ["OID@", "some_field"]) as cursor:
    for row in cursor:
        print row

Alternatively, building on gene's answer, Python's built-in enumerate function can make a clean workflow out of this.

import arcpy

shp = r'X:\path\to\your\shapefile.shp'

with arcpy.da.SearchCursor(shp, "some_field") as cursor:
    for i, row in enumerate(cursor, start = 1):
        print i, row

Note that `enumerate' creates a tuple of a count and the iterable value. To highlight the fuctionality (documentation):

>>> seasons = ['Spring', 'Summer', 'Fall', 'Winter']
>>> list(enumerate(seasons))
[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
>>> list(enumerate(seasons, start=1))
[(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]

Tags:

Cursor

Arcpy

Loop