I'm currently away in a remote field station using Arc 10.0 and having a hard time using an inline variable substitution for a numeric field value. I am trying to use UpdateCursor to select only a specific line by designating a "POSITION" field = to a numeric value that I can increment each time I go through the for loop. When I use a number in the line, it works. However, I can't seem to get the right syntax to substitute the hard-coded number for a variable.

here's the section of code:

## Attempt to update the cursor, then get value, then setvalue using an inline variable for the desired Field value
## THIS does not work
stefile = "ste1.shp"       
stefield = "POSITION"
steclus = "CLUSTER"
steac = "AC"
stevalue = 100
stepos = 22
Z = arcpy.UpdateCursor(stefile, '"POSITION" = stepos')        # This needs to be changed eg; '"POSITION" = a memvar') ...and at end of loop memvar +=1
for row in Z:
    print row.getValue(steclus)                       
    memvar = row.getValue(steclus)                   
    row.setValue(steac, stevalue)                   
    print row.getValue(steac)
    del Z
    del row

### HERE are the error messages
# Runtime error <type 'exceptions.RuntimeError'>: ERROR 999999:
# Error executing function.
# A column was specified that does not exist.

Am I simply using the wrong syntax?


The where clause is currently evaluating stepos literally as the value stepos, not the variable value 22.

Move the stepos variable outside the where clause string, casting the numeric value to a string, like:

arcpy.UpdateCursor(stefile, ' "POSITION" = ' + str(stepos))
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.