update cursor with compound where clause

750
2
Jump to solution
03-27-2023 09:12 AM
clt_cabq
Occasional Contributor III

I want to run an update cursor that operates on a couple of conditions as in the following: 

with arcpy.da.UpdateCursor(fc,field_list) as cursor:
for rec in cursor:
 if rec[0] == 'some value' AND (rec[1]+rec[2] > 9):
     rec[4] = 'updated value'
cursor.updateRow(rec)

essentially, I need to update records for specific values in one field when the sum of two others are at least 1.

However, I keep getting a syntax error at the AND statement.

Bonus points if you have thoughts about looping through multiple conditions being fed into this - for instance, I have 4 different conditions to update in  the 'rec[0] ' field, each of which has a set of conditions to meet and an 'else' result. Can this be done with a dictionary perhaps?

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor

Python is case sensitive, AND does not exist in Python but and does. Suggest you read this page.

View solution in original post

0 Kudos
2 Replies
DuncanHornby
MVP Notable Contributor

Python is case sensitive, AND does not exist in Python but and does. Suggest you read this page.

0 Kudos
clt_cabq
Occasional Contributor III

Thank you, I figured this out just now actually, some confusion on my part caused by the reference material on the update cursor help and its reference to the 'sql reference for query expressions' help page. I also think I wasn't deploying the parentheses correctly. 

0 Kudos