AnsweredAssumed Answered

Calculation error using cursors, second cursor uses first value of first cursor

Question asked by jpfargo on Nov 19, 2013
Latest reply on Nov 20, 2013 by jpfargo
Attempting to add up values of one field based on the value of another field.  The first cursor adds up the values in the field correctly, but the second one uses the first value of the first cursor resulting in a wrong total.  If I replace the code "totalPrice1 = (Row[1])" with "totalPrice1 = 0.0", it just skips the first value entirely. I think the error lies in this code in the second cursor "totalPrice2 = (Row[1])" because it seems to set the value to the first value in the first cursor instead of the first value in the second.  ideas?

Fields = ['Field1','Dollar Value'] FirstCursor = arcpy.da.SearchCursor(fcName,Fields) for Row in FirstCursor:     totalPrice1 = (Row[1])     for Row in FirstCursor:         if Row[0] == "Example 1":             totalPrice1 += (Row[1]) del Row del FirstCursor  SecondCursor = arcpy.da.SearchCursor(fcName,Fields) for Row in SecondCursor:     totalPrice2 = (Row[1]) # Something needs to be changed here to get the first value correct     for Row in SecondCursor:         if Row[0] == "Example 2":             totalPrice2 += (Row[1]) del Row del SecondCursor

Outcomes