I've hit a wall trying to loop through multiple fields with arcpy.UpdateCursor. I have a list of files (2) with multiple fields (10-15'ish) that have its own error check in SQL, and an error value to be written. I am wanting to loop through and update each field with its programmed value.
import arcpy FILE = 'X:\\SOME_FILE' FIELDS = [ "FIELD_X", "...", "FIELD_N"] SQL = "SOME_FIELD = SOME_VALUE" # or less than, greater, etc for FIELD in FIELDS: rows = arcpy.UpdateCursor(FILE, SQL, "", FIELD) row.FIELD = 'FIELD_ERROR_VALUE' rows.updateRow(row) del rows
There's a bit more to it, but the short is that row.FIELD is read as row.'FIELD_NAME', with FIELD_NAME as a string value. I'm rather new to the backside of Python programming and got thrown in just to learn. I've worked through many issues, but this one has got me stumped. If row.FIELD would work, it would be easier than going through each single field with it's NAME, SQL, UPDATE_VALUE, etc manually. It works if I type in row.WHATEVER_FIELD = ..., but calling the variable (from string) adds a ' to both ends as a string value. The only thing not working in the loop is row.FIELD.
I'm working with python2.6, arc10.0, mostly win7.
Any help would be greatly appreciated.