UpdateCursor to update a field value

360
2
Jump to solution
09-29-2016 11:05 AM
CCWeedcontrol
Regular Contributor

I have a basic UpdateCursor to update a field value but for some reason the row with "5280" won't update to "1". It only updates the "10560" to "2".

it's probably something i am over looking but not sure what's going on. Any help would be great.

arcpy.Buffer_analysis(SP, outfile, distance, "OUTSIDE_ONLY", "ROUND", "", "BUFF_DIST")

arcpy.Merge_management(["wp2 Mile","wp1 Mile"], "1_2")

with arcpy.da.UpdateCursor("1_2" , "BUFF_DIST") as cursor:
            for row in cursor:
                if row[0] == 5280:
                    row[0] = '1'
                elif row[0] == 10560:
                    row[0] = '2'
                    cursor.updateRow(row)
            del row

I have tried  else: but i get the same results.

with arcpy.da.UpdateCursor("1_2" , "BUFF_DIST") as cursor:
            for row in cursor:
                if row[0] == 5280:
                    row[0] = '1'
                else:
                    row[0] = '2'
                    cursor.updateRow(row)
            del row
Reply
0 Kudos
1 Solution

Accepted Solutions
BlakeTerhune
MVP Regular Contributor

Your indenting is wrong. Bump your updateRow back four spaces. Or, just add another cursor.updateRow(row) for the first if.

View solution in original post

Reply
0 Kudos
2 Replies
BlakeTerhune
MVP Regular Contributor

Your indenting is wrong. Bump your updateRow back four spaces. Or, just add another cursor.updateRow(row) for the first if.

View solution in original post

Reply
0 Kudos
CCWeedcontrol
Regular Contributor

Thanks!

Reply
0 Kudos