AnsweredAssumed Answered

arcpy.da.UpdateCursor skipping every other record (but kudos for speed)

Question asked by rastrauch Champion on Jan 10, 2012
Latest reply on Jan 11, 2012 by rastrauch
I've created a 10.1 arcpy.da cursor "feeding-in" 13 fields.  I then process the records with a "for theRow in theRows:" with a series of if, elif statements that then assign a code to one field based on the results.  I was using the same if/elif logic that works great in 10.0. but with the new "theRow[]" syntax. 

The code runs thru, but every other record is <null> even though at the very least it should have a value of 9000 which is in my "else:" statement. 

I thought maybe the "theRow = theRows.next()" statement at the end may have caused the problem, but removing these did not help (nor did it seem to hurt).

Anyone have any idea why it would work on every other record? 

BTW - Kudos for the increase speed of both cursors, TableToTable_management, and Joinfield_management in python.  This script used to take over 5 hours, now only 11 minutes...the skipped records not withstanding.  Actually the T2T and JoinField had the most improvement in my script!  thanks!


    theRow, theRows = None, None     theRows = arcpy.da.UpdateCursor(UCU_arc, ['LEFT_FID', 'RIGHT_FID', 'LUCU', 'RUCU',                                                'LGeoDetail', 'RGeoDetail', 'LUnitSub', 'RUnitSub',                                                'LSubMinor', 'RSubMinor', 'LMinorSpecific', 'RMinorSpecific',                                               'LineID'])      #    The values to be using the the 10.1 cursor: #            LEFT_FID and RIGHT_FID:  theRow[0], theRow[1] #      LUCU and RUCU:  theRow[2], theRow[3] #      LGeoDetail and RGeoDetail:  theRow[4], theRow[5] #      LUnitSub and RUnitSub:  theRow[6], theRow[7] #      LSubMinor and RSubMinor:  theRow[8], theRow[9] #      LMinorSpecific and RMinorSpecific:  theRow[10], theRow[11] #      LineID : theRow[12]          # ArcGIS 10.0 version.... #    theRow = theRows.next() #    for theRow in theRows: #        if ((theRow.LEFT_FID == -1) or (theRow.RIGHT_FID == -1)): #            theRow.LineID = 6000 #            theRows.updateRow(theRow) #        elif ((theRow.LUCU == theRow.RUCU) and (theRow.LGeoDetail == 5 or theRow.RGeoDetail == 5)): #            theRow.LineID = 4000 #            theRows.updateRow(theRow) #        elif ((theRow.LUCU == theRow.RUCU) and (theRow.LGeoDetail == 9 or theRow.RGeoDetail == 9)): #            theRow.LineID = 4000 #            theRows.updateRow(theRow) #        elif ((theRow.LUCU == theRow.RUCU) and (theRow.LGeoDetail == 6 or theRow.RGeoDetail == 6)): #            theRow.LineID = 5000 #            theRows.updateRow(theRow) #        elif (theRow.LUnitSub != theRow.RUnitSub): #            theRow.LineID = 1000 #            theRows.updateRow(theRow) #        elif (theRow.LSubMinor != theRow.RSubMinor): #            theRow.LineID = 2000 #            theRows.updateRow(theRow) #        elif ((theRow.LSubMinor == theRow.RSubMinor) and (LMinorSpecific != RMinorSpecific)): #            theRow.LineID = 3000 #            theRows.updateRow(theRow) #        else: #            theRow.LineID = 9000 #            print LineID, LUCU, RUCU #        theRow = theRows.next()          #theRow = theRows.next()     for theRow in theRows:  if ((theRow[0] == -1) or (theRow[1] == -1)):      theRow[12] = 6000      theRows.updateRow(theRow)  elif ((theRow[2] == theRow[3]) and (theRow[4] == 5 or theRow[5] == 5)):      theRow[12] = 4000      theRows.updateRow(theRow)  elif ((theRow[2] == theRow[3]) and (theRow[4] == 9 or theRow[5] == 9)):      theRow[12] = 4000      theRows.updateRow(theRow)  elif ((theRow[2] == theRow[3]) and (theRow[4] == 6 or theRow[5] == 6)):      theRow[12] = 5000      theRows.updateRow(theRow)  elif (theRow[6] != theRow[7]):      theRow[12] = 1000      theRows.updateRow(theRow)  elif (theRow[8] != theRow[9]):      theRow[12] = 2000      theRows.updateRow(theRow)  elif ((theRow[8] == theRow[9]) and (theRow[10] != theRow[11])):      theRow[12] = 3000      theRows.updateRow(theRow)  else:      theRow[12] = 9000      print theRow[12], theRow[4], theRow[5]              #finally:         # Regardless of whether the script succeeds or not, delete          #  the row and cursor         #     if theRow:         del theRow     if theRows:         del theRows

Outcomes