1

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)                   
    Z.updateRow(row)
    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?

0

1 Answer 1

2

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))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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