[GIS] ArcPy Cursor iteration update

arcpycursor

I'm trying to get the cursor to iterate through rows and fields looking for blank or null values and change them to 999999 but it's not changing anything.

fc = "C:\Users\\bbrock\Documents\ArcGIS\Ports.shp"

# Create a search cursor 
#
rows = arcpy.SearchCursor(fc) 

# Create a list of string fields
fields = arcpy.ListFields(fc, "", "String")

for row in rows:
    for field in fields:
        if field.type != "Geometry":
            if row.getValue(field.name) == '':
                row.setValue(field.name, '999999')              
                print "%s: Value = %s" % (field.name, row.getValue(field.name))

            if row.isNull(field.name):
                row.setValue(field.name, '999999')              
                print "%s: Value = %s" % (field.name, row.getValue(field.name))             

Best Answer

A SearchCursor is read-only. You want to use an UpdateCursor. Also don't forget to call the cursor's updateRow method after setting a row's values.

See Accessing data using cursors in the help for more information.