<?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 Re: Python Script for &amp;quot;Select by Attributes &amp;quot; in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/python-script-for-amp-quot-select-by-attributes/m-p/82629#M2841</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks, I will try this tomorrow morning and reply as to the outcome.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;George&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 28 Oct 2010 01:24:11 GMT</pubDate>
    <dc:creator>GeorgeBentley</dc:creator>
    <dc:date>2010-10-28T01:24:11Z</dc:date>
    <item>
      <title>Python Script for &amp;quot;Select by Attributes &amp;quot;</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-for-amp-quot-select-by-attributes/m-p/82627#M2839</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello Everyone,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am working on a python script that is progressing nicely.&amp;nbsp; I am having an issue when I am trying to use the "Select by Attribute" tool.&amp;nbsp; I have posted the post below for reference.&amp;nbsp; In the BID field of the Final_Intersection file I want to select where BID = 1 and then export these selected records to a new file.&amp;nbsp; I would greatly appreciate any help that could be offered.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The error that is returned is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "F:/Dr_Cromley/Python_Work/GCB_DZ_Trial.py", line 62, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SelectLayerByAttribute("temp_lyr", "NEW_SELECTION","[BID] = '1'")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ExecuteError: ERROR 000358: Invalid expression&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (SelectLayerByAttribute).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is a version of the Python script:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import sys&amp;nbsp; # Imports the sys module.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import os # Imports the operating system module&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcgisscripting # Imports the arcgisscripting module&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import string # Imports the string module&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import math # Imports the math module&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create(9.3) # Creates the geoprocessor by using the create method of the arcgisscripting module.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.SetProduct('ArcInfo') # Sets the selection of ArcTools to the ArcEditor level.&amp;nbsp; Not necessary in this case but included for demonstration.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.OverwriteOutput = 1 # Setting the value to 1 allows for outputs to be overwritten.&amp;nbsp; A value of 0 would prevent outputs from being overwritten and make it more difficult to run the script more than once.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.Workspace = r"D:\Dr_Cromley\Python_Work\Python_Data"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;###gp.Workspace = sys.argv[1] # Sets the workspace for the data so that the user does not need to type in full pathname.&amp;nbsp; ## Will be set as system parameter.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;###Sourcefile = sys.argv[2] # Creates a system parameter for user to input the source file that will be used in ArcGIS.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;###Targetfile = sys.argv[3] # Creates a system parameter for the user to input the target file that will be used in ArcGIS.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;###gp.AddToolBox (r"C:\Program Files\ArcGIS\ArcToolbox\Toolboxes\Data Management Tools.tbx") # Adds the tools within the Data Management ToolBox&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;###gp.AddToolBox (r"C:\Program Files\ArcGIS\ArcToolbox\Toolboxes\Analysis Tools.tbx") # Adds the tools within the Analysis ToolBox&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Srcfile = r"D:\Dr_Cromley\Python_Work\Python_Data\CT_POP_LC_FIX_FIN.shp" #Setting the source shapefile equal to the census tract shapefile for the testing purposes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Trgtfile = r"D:\Dr_Cromley\Python_Work\Python_Data\BG_POP_LC_FIX_FIN.shp" #Setting the target shapefile equal to the block group shapefile for the testing purposes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Cntrlfile = r"D:\Dr_Cromley\Python_Work\Python_Data\landcover_polygon.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;##gp.AddField_management (Srcfile, "S_Area", "DOUBLE", 15, 10, "", "", "", "", "") #Adding a double field with scale of 15 and precision of 10 to the intersection file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##gp.CalculateField_management (Srcfile, "S_Area", "(float(!SHAPE.AREA!))", "PYTHON_9.3", "")&amp;nbsp; #Setting the Calculate Field tool to calculate the area of the census tract or source file inside of the Src_Area field created above. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##gp.Dissolve_management (Cntrlfile, "LC_Control_Dissolve.shp", "BID", "", "MULTI_PART", "UNSPLIT_LINES") &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##Dissolve_Output1 = "LC_Control_Dissolve.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##gp.Dissolve_management (Dissolve_Output1, "LC_Control_Dissolve_2.shp", "BID", "", "MULTI_PART", "UNSPLIT_LINES")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##Inputs = "%s;%s" % (Srcfile,Trgtfile) #Uses variable substitution to create one input variable to be used in the intersection tool so to avoid the problem of having the script crash when there are more than one input variables.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##Intersection_Layer = "Intersection_Source_Target_Dasy.shp"&amp;nbsp; #Creates a variable name for the Intersection_Source_Target_Dasy.shp that is a created as a result of the first intersection.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##gp.Intersect_analysis (Inputs, Intersection_Layer, "ALL", "", "INPUT")&amp;nbsp; #Runs the intersect for the areal interpolation analysis.&amp;nbsp; Due to the problems with the multiple input variables, the file along with their pathnames had to be used to continue&amp;nbsp; writing the script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##LC_Control_Dissolve_2 = "LC_Control_Dissolve_2.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##Inputs_2nd = "%s;%s" % (Intersection_Layer, LC_Control_Dissolve_2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Final_Intersection = "Intersection_Intrsct_LCCntrlDsslve2.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##gp.Intersect_analysis (Inputs_2nd, Final_Intersection, "ALL", "", "INPUT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##gp.AddField_management (Final_Intersection, "FI_Area", "DOUBLE", 15, 10, "", "", "", "", "") #Adding a double field with scale of 15 and precision of 10 to the intersection file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##gp.CalculateField_management (Final_Intersection, "FI_Area", "(float(!SHAPE.AREA!))", "PYTHON_9.3", "")&amp;nbsp; #Setting the Calculate Field tool to calculate the area of the census tract or source file inside of the Src_Area field created above. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;##&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.MakeFeatureLayer(Final_Intersection,"temp_lyr") &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.SelectLayerByAttribute("temp_lyr", "NEW_SELECTION","[BID] = '1'")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Oct 2010 20:40:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-for-amp-quot-select-by-attributes/m-p/82627#M2839</guid>
      <dc:creator>GeorgeBentley</dc:creator>
      <dc:date>2010-10-27T20:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script for "Select by Attributes "</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-for-amp-quot-select-by-attributes/m-p/82628#M2840</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This is a stupid syntax thing with .shp and .dbf files, but try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.SelectLayerByAttribute("temp_lyr", "NEW_SELECTION","\"BID"\" = '1'") &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if it was in FGDB it would just be:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.SelectLayerByAttribute("temp_lyr", "NEW_SELECTION","BID = '1'")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Oct 2010 22:46:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-for-amp-quot-select-by-attributes/m-p/82628#M2840</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-10-27T22:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script for "Select by Attributes "</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-for-amp-quot-select-by-attributes/m-p/82629#M2841</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks, I will try this tomorrow morning and reply as to the outcome.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;George&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Oct 2010 01:24:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-for-amp-quot-select-by-attributes/m-p/82629#M2841</guid>
      <dc:creator>GeorgeBentley</dc:creator>
      <dc:date>2010-10-28T01:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script for "Select by Attributes "</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-for-amp-quot-select-by-attributes/m-p/82630#M2842</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I gave this line a try this morning&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.SelectLayerByAttribute("temp_lyr", "NEW_SELECTION","\"BID"\" = '1'")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A syntax error of "There's an error in your program:&amp;nbsp; unexpected character after line continuation character." is returned.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I believe it is the second \ that is creating the problem but am unsure how to fix it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;George&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Oct 2010 12:42:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-for-amp-quot-select-by-attributes/m-p/82630#M2842</guid>
      <dc:creator>GeorgeBentley</dc:creator>
      <dc:date>2010-10-28T12:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script for "Select by Attributes "</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-for-amp-quot-select-by-attributes/m-p/82631#M2843</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;George, Sorry to lead you astray:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Seems the "\"\ thing for .shp and .dbf formats is no longer neccessary in v9.3.1. Try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;gp.SelectLayerByAttribute("temp_lyr", "NEW_SELECTION", "BID = '1'")&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;or if the BID field is numeric, then just this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;gp.SelectLayerByAttribute("temp_lyr", "NEW_SELECTION","BID = 1")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Oct 2010 15:25:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-for-amp-quot-select-by-attributes/m-p/82631#M2843</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-10-28T15:25:43Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script for "Select by Attributes "</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-for-amp-quot-select-by-attributes/m-p/82632#M2844</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Chris,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This suggestion worked.&amp;nbsp; Thanks for your help, it is greatly appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;George&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Nov 2010 12:53:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-for-amp-quot-select-by-attributes/m-p/82632#M2844</guid>
      <dc:creator>GeorgeBentley</dc:creator>
      <dc:date>2010-11-04T12:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script for &amp;quot;Select by Attributes &amp;quot;</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-for-amp-quot-select-by-attributes/m-p/82633#M2845</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;is there a way to put also BIS = max(c)? Let's say that c is a numeric field&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Mar 2015 00:21:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-for-amp-quot-select-by-attributes/m-p/82633#M2845</guid>
      <dc:creator>KONPETROV</dc:creator>
      <dc:date>2015-03-31T00:21:42Z</dc:date>
    </item>
  </channel>
</rss>

