<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic User Input into Selection Expression in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/user-input-into-selection-expression/m-p/168440#M12987</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to write a script that will simply get (1) a county name and (2) and tax parcel ID. These values (stored as variables) need to be used in a SQL expression for the Select by Attribute dialog. This model needs to run in ArcMap, so I'm not sure if the "input" is correct usage and whether I've properly written the SQL expression to handle the variables (county name, parcel ID). &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;________________________________&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import modules&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import sys&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Set local variables&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;parcels="Parcels"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Ask user for the County and Parcel ID to search&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;county = input("Please type either WARREN, WASHINGTON, OR ESSEX: ")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;key = input("Please type the Parcel ID: ")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# User selects COUNTY and then Print Key value, Select by Attribute tool runs&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(Parcels, "NEW_SELECTION", "[COUNTY] = 'county' AND [PRINT_KEY] = 'key'")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 20 Oct 2011 20:07:54 GMT</pubDate>
    <dc:creator>SheriNorton</dc:creator>
    <dc:date>2011-10-20T20:07:54Z</dc:date>
    <item>
      <title>User Input into Selection Expression</title>
      <link>https://community.esri.com/t5/python-questions/user-input-into-selection-expression/m-p/168440#M12987</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to write a script that will simply get (1) a county name and (2) and tax parcel ID. These values (stored as variables) need to be used in a SQL expression for the Select by Attribute dialog. This model needs to run in ArcMap, so I'm not sure if the "input" is correct usage and whether I've properly written the SQL expression to handle the variables (county name, parcel ID). &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;________________________________&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import modules&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import sys&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Set local variables&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;parcels="Parcels"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Ask user for the County and Parcel ID to search&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;county = input("Please type either WARREN, WASHINGTON, OR ESSEX: ")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;key = input("Please type the Parcel ID: ")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# User selects COUNTY and then Print Key value, Select by Attribute tool runs&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(Parcels, "NEW_SELECTION", "[COUNTY] = 'county' AND [PRINT_KEY] = 'key'")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Oct 2011 20:07:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/user-input-into-selection-expression/m-p/168440#M12987</guid>
      <dc:creator>SheriNorton</dc:creator>
      <dc:date>2011-10-20T20:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: User Input into Selection Expression</title>
      <link>https://community.esri.com/t5/python-questions/user-input-into-selection-expression/m-p/168441#M12988</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I believe you will want to use the 'raw_input' function to do this.&amp;nbsp; Here is an example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
env.overwriteOutput = 1

county = raw_input("Please type either WARREN, WASHINGTON, OR ESSEX: ")
key = raw_input("Please type the Parcel ID: ")

# User selects COUNTY and then Print Key value, Select by Attribute tool runs
arcpy.MakeFeatureLayer_management("Parcels", "Parcels_feat")
arcpy.SelectLayerByAttribute_management("Parcels_feat", "NEW_SELECTION", "COUNTY = " + "'" + county + "'")
arcpy.SelectLayerByAttribute_management("Parcels_feat", "NEW_SELECTION", "PARCELS_ID = " + key)
arcpy.CopyFeatures_management("Parcels_feat", "Parcels_Selection")
print "Executed succesfully"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This will prompt the user for a county name and a parcel ID.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:45:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/user-input-into-selection-expression/m-p/168441#M12988</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T08:45:53Z</dc:date>
    </item>
  </channel>
</rss>

