firstTime = True for row in rows: if firstTime: myMeas = row.getValue('MEAS') #in your first iteration you will not have anything to update you just need to get the value for the next iteration firstTime = False else: row.setValue('MEASCalc', row.getValue('MEAS') - myMeas rows.updateRow(row) myMeas = row.getValue('MEAS') #get the value for the next iteration
rows = UpdateCursor(...) count = 0 for row in rows: if count != 0: # if this isn't the first time in the loop (ie. if you have a number to subtract) count = count + 1 row.blankcolumnname = row.MEAS - previous # make the blank column = current - previous rows.updateRow(row) # updates the whole row, now with a value for the blank column previous = row.MEAS # sticks the current value into the previous variable for the next time through the loop del row del rows # remove row locks
import arcpy
rows = arcpy.UpdateCursor(FILL IN YOUR PARAMETERS HERE)
import arcpy myFile = "c:/gis/temp.shp" sortField = "MEAS" newField = "NEW" rows = arcpy.UpdateCursor(myFile,"","","",sortField + " A") # sort by sort field firstTime = True for row in rows: if firstTime: previous = row.getValue(sortField) #in your first iteration you will not have anything to update you just need to get the value for the next iteration firstTime = False else: row.setValue(newField, row.getValue(sortField) - previous) rows.updateRow(row) previous = row.getValue(sortField) #get the value for the next iterationexcept: del row del rows
for row in rows: if count != 0: # if this isn't the first time in the loop (ie. if you have a number to subtract) count = count + 1 row.blankcolumnname = row.MEAS - previous # make the blank column = current - previous rows.updateRow(row) # updates the whole row, now with a value for the blank column previous = row.MEAS # sticks the current value into the previous variable for the next time through the loop else: # do this if it is the first time in the loop count = 1 previous = row.MEAS