In the Python code inside a Calculate Value tool in my model, I have the following:
getNum("%Selected Features%")
def getNum(ftr):
lst = [4, 11, 15] #values for SQL expression
x = 20
fields = ('TYPE_A', 'TYPE_B', 'NUM_ID')
for l in lst:
y = x + 1
whereclause = """"NUM_ID" = %s """ % l
with arcpy.da.UpdateCursor(ftr, fields, whereclause) as cursor:
for row in cursor:
if row[0] ! = row[1]:
row[2] = y
cursor.updateRow(row)
y += 1
What I would like to do is, for every element in lst, create a cursor based on a selection of records where NUM_ID = l. The values in TYPE_A and TYPE_B should be compared for each record and updated if necessary.
The script is failing after the cursor is created, with the error Item not in collection. If I remove the whereclause, it executes. Once the records have been selected and the values compared and updated if necessary, I need to increment the counter y by 1. I think I'm doing it in the wrong place though, because if I run the script without the whereclause it does execute correctly.When I check the records with the changed values, they are now all set to y, which indicates that y was not incremented.
y. – Cindy Jayakumar Jan 30 '13 at 05:14