Solved! Go to Solution.
ERROR 000539: Error running expression: CalcDiff(r"C:\Export_Output.dbf", "PIPELENGTH", "DISTANCE") <type 'exceptions.TypeError'>: 'geoprocessing cursor object' object is not iterable
Failed to execute (CalculateValue).
import arcgisscripting gp = arcgisscripting.create(9.3) def CalcDiff(tbl,valField,diffField): procFields = valField + ";" + diffField sortField = valField Rows = gp.UpdateCursor(tbl, "", "", procFields, sortField) lastVal = 0 Row = Rows.next() while Row: val = float(Row.getValue(valField)) # calc the difference between the last value and this one diff = val - lastVal Row.setValue(diffField,diff) Rows.updateRow(Row) lastVal = val Row = Rows.next() del Row, Rows return tbl
The sort ascending must also be done in the field calculator before doing the calculation.
import arcgisscripting gp = arcgisscripting.create(9.3) def CalcDiff(tbl,valField,diffField): procFields = valField + ";" + diffField sortField = valField Rows = gp.UpdateCursor(tbl, "", "", procFields, sortField) lastVal = 0 for Row in Rows: val = float(Row.getValue(valField)) # calc the difference between the last value and this one diff = val - lastVal Row.setValue(diffField,diff) Rows.updateRow(Row) lastVal = val del Row, Rows return tbl
ERROR 000539: Error running expression: CalcDiff(r"C:\Export_Output.dbf", "PIPELENGTH", "DISTANCE") <type 'exceptions.TypeError'>: 'geoprocessing cursor object' object is not iterable
Failed to execute (CalculateValue).
import arcgisscripting gp = arcgisscripting.create(9.3) def CalcDiff(tbl,valField,diffField): procFields = valField + ";" + diffField sortField = valField Rows = gp.UpdateCursor(tbl, "", "", procFields, sortField) lastVal = 0 Row = Rows.next() while Row: val = float(Row.getValue(valField)) # calc the difference between the last value and this one diff = val - lastVal Row.setValue(diffField,diff) Rows.updateRow(Row) lastVal = val Row = Rows.next() del Row, Rows return tbl
What is the syntax I should be using? Thanks.
import arcpy def CalcDiff(tbl,valField,diffField): procFields = valField + ";" + diffField sortField = valField Rows = gp.UpdateCursor(tbl, "", "", procFields, sortField) lastVal = 0 while Row: val = float(Row.getValue(valField)) # calc the difference between the last value and this one diff = val - lastVal Row.setValue(diffField,diff) Rows.updateRow(Row) lastVal = val del Row, Rows return tbl