1

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
  • 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. Commented Feb 8, 2019 at 22:22

1 Answer 1

3

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.