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')  
  • 2
    Welcome to GIS SE. As a new user, please take the Tour. I would suggest you list the documentation pages for non-DataAccess cursors with blocking software, so that you are not even permitted to view them. All new arcpy cursor work should only be done with Data Access cursors (e.g. 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 debug print statements, and list output. – Vince Feb 8 '19 at 22:22

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'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.