I am trying to loop through a list of states, and use each state as a variable within a where clause to select by attribute. Below is the code I am trying to run. Note: I will eventually be running this with every state in stateList. I only have Wisconsin in there for testing purposes.
1 import arcpy, sys, os
2
3 # Set current directory
4 root = os.getcwd()
5
6 # Hardcoded FGDB
7 inFGDB = "C:/test/file.gdb"
8
9 arcpy.env.workspace = inFGDB
10
11 stateList = ["Wisconsin"]
12
13 arcpy.MakeFeatureLayer_management(inFGDB+"/MapAdminArea","MapArea")
14
15 arcpy.AddJoin_management("MapArea","ADMIN_PLACE_ID","Admin","ADMIN_PLACE_ID")
16
17 for st in stateList:
18 qry = '"Admin.ORDER1_NAME" = ' + "'" +st+ "'"
19 arcpy.SelectLayerByAttribute_management("MapArea","NEW_SELECTION",qry)
20 arcpy.RemoveJoin_management("MapArea")
21 arcpy.CopyFeatures_management("MapArea","MapArea_"+st)
The select statement on line 19 is giving me an Invalid expression error. If I replace line 19 this this Select statement: arcpy.SelectLayerByAttribute_management("MapArea","NEW_SELECTION","Admin.ORDER1_NAME ='Wisconsin'") it selects Wisconsin as expected. I am hoping I can figure out the correct formatting for qry to select and export each individual state from a North America dataset.