<?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 Selecting by Attribute - help in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/selecting-by-attribute-help/m-p/712203#M55235</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Im trying to write a code that will be used as a tool on arcgis. The user will have to insert the number of a Block and the Number of a Parcel in 1 shapefile and the tool will create a JPEG map of the Block and Parcel. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The 1st thing i need to do is to select the correct Parcel and Block (Gush = Block, Helka = Parcel). The field for Gush in the shapefile is "GUSH_NUM", and the field for Helka is "Parcel"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So both Gush and Helka will have to be arcpy.GetParameterAsText, and using a variable in the where clause of the select by attribute tool. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But how do i write it in the where clause of the select by attribute tool?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried using this post for help: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://forums.arcgis.com/threads/20459-Select-By-Attributes-using-a-variable-in-the-Where-clause?highlight=Select+attributes" rel="nofollow" target="_blank"&gt;http://forums.arcgis.com/threads/20459-Select-By-Attributes-using-a-variable-in-the-Where-clause?highlight=Select+attributes&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So i tried writing the where clause as the post suggests but it still doesnt work. I get an error - invalid expression.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my code so far, i tried only on the Gush for now.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Will apriciate any help. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# Import the arcgisscripting module. import arcpy&amp;nbsp; # Setting the Variabls.&amp;nbsp; # Input gush and Helka. Gush = arcpy.GetParameterAsText(0) Helka = arcpy.GetParameterAsText(1)&amp;nbsp; # Output Location (the folder where the resualt will be saved). Workspace = arcpy.GetParameterAsText(2)&amp;nbsp; arcpy.env.workspace = Workspace&amp;nbsp;&amp;nbsp; hel_openland_shp = "W:\\Av_data\\cover_new\\mamag_mapi\\hel_openland.shp" Output_Layer = "hel_openland_Layer"&amp;nbsp; arcpy.MakeFeatureLayer_management(hel_openland_shp, Output_Layer)&amp;nbsp; arcpy.SelectLayerByAttribute_management(Output_Layer, "NEW_SELECTION", "\"GUSH_NUM\" = " + "'" + Gush + "'")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 21 Aug 2012 09:30:11 GMT</pubDate>
    <dc:creator>IlanGoichman</dc:creator>
    <dc:date>2012-08-21T09:30:11Z</dc:date>
    <item>
      <title>Selecting by Attribute - help</title>
      <link>https://community.esri.com/t5/python-questions/selecting-by-attribute-help/m-p/712203#M55235</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Im trying to write a code that will be used as a tool on arcgis. The user will have to insert the number of a Block and the Number of a Parcel in 1 shapefile and the tool will create a JPEG map of the Block and Parcel. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The 1st thing i need to do is to select the correct Parcel and Block (Gush = Block, Helka = Parcel). The field for Gush in the shapefile is "GUSH_NUM", and the field for Helka is "Parcel"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So both Gush and Helka will have to be arcpy.GetParameterAsText, and using a variable in the where clause of the select by attribute tool. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But how do i write it in the where clause of the select by attribute tool?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried using this post for help: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://forums.arcgis.com/threads/20459-Select-By-Attributes-using-a-variable-in-the-Where-clause?highlight=Select+attributes" rel="nofollow" target="_blank"&gt;http://forums.arcgis.com/threads/20459-Select-By-Attributes-using-a-variable-in-the-Where-clause?highlight=Select+attributes&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So i tried writing the where clause as the post suggests but it still doesnt work. I get an error - invalid expression.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my code so far, i tried only on the Gush for now.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Will apriciate any help. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# Import the arcgisscripting module. import arcpy&amp;nbsp; # Setting the Variabls.&amp;nbsp; # Input gush and Helka. Gush = arcpy.GetParameterAsText(0) Helka = arcpy.GetParameterAsText(1)&amp;nbsp; # Output Location (the folder where the resualt will be saved). Workspace = arcpy.GetParameterAsText(2)&amp;nbsp; arcpy.env.workspace = Workspace&amp;nbsp;&amp;nbsp; hel_openland_shp = "W:\\Av_data\\cover_new\\mamag_mapi\\hel_openland.shp" Output_Layer = "hel_openland_Layer"&amp;nbsp; arcpy.MakeFeatureLayer_management(hel_openland_shp, Output_Layer)&amp;nbsp; arcpy.SelectLayerByAttribute_management(Output_Layer, "NEW_SELECTION", "\"GUSH_NUM\" = " + "'" + Gush + "'")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Aug 2012 09:30:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-by-attribute-help/m-p/712203#M55235</guid>
      <dc:creator>IlanGoichman</dc:creator>
      <dc:date>2012-08-21T09:30:11Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting by Attribute - help</title>
      <link>https://community.esri.com/t5/python-questions/selecting-by-attribute-help/m-p/712204#M55236</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok, i feel a little foolish. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I looked in another post: &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/65128-ArcPy-script-in-toolbox-what-do-I-do-about-optional-parameters" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.arcgis.com/threads/65128-ArcPy-script-in-toolbox-what-do-I-do-about-optional-parameters&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and found the answer and it works! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;the correct code is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import the arcgisscripting module.
import arcpy

# Setting the Variabls.

# Input gush and Helka.
Gush = arcpy.GetParameterAsText(0)
Helka = arcpy.GetParameterAsText(1)

# Output Location (the folder where the resualt will be saved).
Workspace = arcpy.GetParameterAsText(2)

arcpy.env.workspace = Workspace


hel_openland_shp = "W:\\Av_data\\cover_new\\mamag_mapi\\hel_openland.shp"
Output_Layer = "hel_openland_Layer"

arcpy.MakeFeatureLayer_management(hel_openland_shp, Output_Layer)

arcpy.SelectLayerByAttribute_management(Output_Layer, "NEW_SELECTION", &lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;"\"GUSH_NUM\" = "+ Gush&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:31:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-by-attribute-help/m-p/712204#M55236</guid>
      <dc:creator>IlanGoichman</dc:creator>
      <dc:date>2021-12-12T06:31:09Z</dc:date>
    </item>
  </channel>
</rss>

