1

I'm just trying to make it where the user types what county they want and the script selects those features.

import arcpy

County = arcpy.GetParameterAsText(0)    

arcpy.env.workspace = (GDB path)

SelectedField = "COUNTY1"

Expression = (SelectedField + '=' + 'County')

arcpy.SelectLayerByAttribute_management("ArmoringBackup", "New_Selection", Expression)

If I put the county name in the expression, it works fine. The issue I'm having is with making it a parameter that can be changed.

1

1 Answer 1

1

Here's the new script after figuring it out (still getting used to this website):

import arcpy

arcpy.env.workspace = r'(GDB Path)'

selectedField = 'COUNTY1'
county = arcpy.GetParameterAsText(0)

sql = "{0} = '{1}'".format(arcpy.AddFieldDelimiters(datasource="ArmoringBackup", field='COUNTY1'), county)
arcpy.SelectLayerByAttribute_management("ArmoringBackup", "New_Selection", sql)

I must've been using the wrong delimiters and the new line does it for you.

1
  • 1
    Best practice calls for only using leading uppercase for class names, not variables.
    – Vince
    Commented May 14, 2021 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.