In this example, a unique value is calculated for each record starting with 1. The result is 1, 2, 3 … to the number of records. This is often necessary when you have to do some spatial operation and perform a join or relate using that field. It can also be useful when your table doesn’t have an OBJECTID field.
This code uses the data access module available with ArcGIS 10.1.
import arcpy with arcpy.da.UpdateCursor(r"C:\Data\city.gdb\crime", "UID") as rows: for i, row in enumerate(rows, 1): row = i rows.updateRow(row)