I have two layers 1. Buffer zones with a string ID 2. the same buffer zones with the String ID plus an extra field call it zone B
*this process is taking place within a loop already, just to give some scope
Objective - extract all of the first layers buffer ID's and use a select by attributes QRY on the second layer to select the first layer zones that are only labeled zone B
What I have done so far:
-extract ID's from first layer store it in a list then tuple
Zonelist = []
for x in gp.SearchCursor(layer1):
ID = x.ID
Zonelist.append(ID)
ZoneTuple = tuple(Zonelist)
now I want to construct a QRY for layer2 that selects all the ID's in the tuple and equal zone b
*I am storing the ID's into a tuple to emulate the parenthesis SQL syntax when using the IN operator within Arcmap
layer2QRY = "ID IN {} AND Labelr = 'ZoneB'".format(ZoneTuple)
layer2 = arcpy.MakeFeatureLayer_management(Allzones, "layer2select", layer2QRY)
Update: the QRY works when there are multiple ID's in the tuple. However when there is only one ID in the tuple ex. ('4321',) a comma appears after the one object and it throws an execute error