1

I'm currently applying a select by attribute query to select null values before applying an increment cursor, but I'm interested in reducing the code by using a where clause and employing the updated da module. Current code:

arcpy.MakeFeatureLayer_management (fc, "fc_update")
gisID = "GIS_2016_0"
where_clause = 'GIS_2016_0 IS NULL'
MaxValue = 1000

def autoIncrement (start=0, step=1):
    i = start
    while 1:
         yield i
         i+=step 

nextValue = MaxValue + 2
incrementer = autoIncrement (nextValue, 2)
with arcpy.da.UpdateCursor ("fc_update", gisID, where_clause) as incrementCursor:
print "Populating fields with no IDs"
    for row in incrementCursor:
        row.setValue(gisID, incrementer.next())
        incrementCursor.updateRow(row)
    del row, incrementCursor
    print "Finished populating null fields"

I get the error AttributeError: 'list' object has no attribute 'setValue'

I'm not certain about how to adapt the increment statements to accommodate a da update cursor, or if my where_clause statement even works.

  • 2
    You are confusing ArcPy.da cursor syntax with ArcPy cursor syntax so I would recommend reviewing the samples in the documentation of the former. – PolyGeo Feb 9 '17 at 18:57
2

You are mixing syntax between arcpy.UpdateCursor() and arcpy.da.UpdateCursor(). As @PolyGeo recommends, you should read up on the documentation for arcpy.da.UpdateCursor().

print "Populating fields with no IDs"
with arcpy.da.UpdateCursor ("fc_update", gisID, where_clause) as incrementCursor:
    for row in incrementCursor:
        row[0] = incrementer.next()
        incrementCursor.updateRow(row)
print "Finished populating null fields"

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.