Hello,
I am working on script to loop through three counties and create layers of the cities contained in each by means of a where clause. My script below will work if instead of a for loop, I just put one county into the where clause. However, when I execute this in pro, it returns three blank county layers. Is there something wrong with my formatted string in the where clause?
cities = r"E:\Users\Documents\ArcGIS\Projects\Practice\Practice.gdb\incorpcity"
counties = r"E:\Users\Documents\ArcGIS\Projects\Practice\Practice.gdb\Countygdb"
outpath = r"E:\Users\Documents\ArcGIS\Projects\Practice\Practice.gdb"
arcpy.env.overwriteOutput = True
counties_of_interest = ['Contra Costa County', 'Alameda County', 'Solano County']
arcpy.management.MakeFeatureLayer(cities, 'cities_temp')
for county in counties_of_interest:
arcpy.management.MakeFeatureLayer(counties, 'counties_temp', """ COUNTY_NAME = '{}' """.format(county))
arcpy.management.SelectLayerByLocation('cities_temp', 'WITHIN', 'counties_temp')
county_1 = county.replace(" ", "_")
arcpy.conversion.FeatureClassToFeatureClass('cities_temp', outpath, f'cities_{county_1}')