rralbritton

Acripting for unknown number of arguments into a SQL statement

Discussion created by rralbritton on Oct 2, 2012
Latest reply on Oct 17, 2012 by rralbritton1981
I am writing a script to select out one or  more counties depending on user input. I can get the script to work if I hardcode the SQL statement with the desired county, however, if I try to make the SQL statement contain an sys.argv[] statement in place of hardcoding a county name the script runs but returns an empty featureclass. Not sure how to make this work?

Thinking ahead, the current script is set up to only takes one argument, but future uses will most likely require an unknown number of arguments. For example, one user may need to select out three counties, another five, etc. Is this possible?

import arcpy, sys

#Set Workspace
arcpy.env.workspace=sys.argv[1]
arcpy.env.overwriteOutput=True

#Select all county(s) of interest

inSelect="CountyBoundary.shp"
outSelect="SelectedCounties.shp"
Where="\"CO_NAME\"='sys.argv[2]'"
arcpy.Select_analysis(inSelect,outSelect,Where)

print arcpy.GetMessages()
print outSelect

Outcomes