I am trying to perform a query based on values in a Python list. The where clause will then be used in an Update Cursor, so that the rows NOT equal to the values in the list will be deleted.
This is what the list will look like after it is passed into the script from the user (using a multivalue parameter in the script tool), and the semicolon delimited string has been split. This is just an example of many choices the user can make.
userSelectionList = ["40","77","95] selectionQRY = "RTE_1_NBR <> 'userSelectionList'" # <-- I know this doesn't work
Hard coded, it would look like:
selectionQRY = "RTE_1_NBR <> '40' AND RTE_1_NBR <> '77' AND RTE_1_NBR <> '95'"
But the input and number of selection depends on the user's selection.
It should finally be something like this:
userSelectionList = ["40","77","95] selectionQRY = "RTE_1_NBR <> 'userSelectionList'" with arcpy.da.UpdateCursor(userI,["RTE_1_NBR"],selectionQRY) as userUC: for row in userUC: userUC.deleteRow() del userUC
Is it possible to make the where clause from a user input/dynamic Python list?