Before I begin I should emphasise that my python knowledge is pretty limited; generally self taught or inspired by snippets I have found on here.
I have a .dbf table, and I need to use python to increment values (row above + 1) in a field ONLY when a value in another field is 0. For all other rows the value is 1. To better illustrate this, when it is complete the table should look something like this:
FID Value Increment 0 1 0 1 1 0 2 1 0 3 1 0 4 0 1 5 0 2 6 0 3 7 0 4 8 1 4 9 1 4 10 1 4 11 1 4 12 0 5
Using the code from the top answer to Computing new attribute based on changes in another attribute using ArcGIS Desktop with Python?
I edited the code to look like this:
import arcpy fc = arcpy.GetParameterAsText(0) rows = arcpy.UpdateCursor(fc) increment = 0 for row in rows: if row.VALUE == 0: increment += 1 row.INCREMENT = increment rows.updateRow(row) while row.VALUE == 1: row.INCREMENT = increment rows.updateRow(row) rows.next() row.INCREMENT = increment rows.updateRow(row) del row, rows
I run it, and it takes quite a while (I have about 11,000 records in the table), before I get this error:
Traceback (most recent call last): File "C:\scratch\incrementLine_IncreFieldEverytimeIncrementChanges.py", line 16, in <module> rows.updateRow(row) File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\arcobjects\arcobjects.py", line 102, in updateRow return convertArcObjectToPythonObject(self._arc_object.UpdateRow(*gp_fixargs(args))) RuntimeError: ERROR 999999: Error executing function.
The thing is though, the code DOES work, it gives me the result in the table that I want, but due to this error I can't slot this script into my ModelBuilder flow, which is rather frustrating!
So my question is, what is causing this error? As I said, the script is editing the table how I want it, so if there is way I can just stop the error so I can use it in a flow that would be ideal! I imagine my limited knowledge in python (and scripting in general) is making me miss something entirely obvious, and also the fact that I'm basically ripping off a script from 2012 could be introducing out of date techniques?