I need to update attributes with arcpy.updateCursor and updateRow based on a list of service numbers, but I can't even get one row to update. This is my beginner code.
df= r"GAS FEATURES\SERVICE GROUP\Gas Service Point"
rows = arcpy.UpdateCursor(df)
for row in rows:
----if row.getValue("SERVICENUMBER")= '02753-725':
----row.SetValue("SubtypeCD",'Multiple Meter Service')
----rows.updateRow(row)
Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Feb 8, 2019 at 21:59
1 Answer 1
Use the data access cursors:
import arcpy
fc = r'C:\data.gdb\somefeature'
fields = ['SERVICENUMBER','SubtypeCD']
with arcpy.da.UpdateCursor(fc,fields) as cursor:
for row in cursor:
if row[0] == '02753-725':
row[1] = 'Multiple Meter Service'
cursor.updateRow(row)
answered Feb 9, 2019 at 6:29
lang-py
arcpy.da.UpdateCursor
). This will save you pain and time. Please Edit your question to specify the exact release of ArcGIS in use, to use DA cursors, to indent the code properly with the{}
formatting button, include some debugprint
statements, and list output.