<?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: problem with SelectLayerByAttribute management in script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/problem-with-selectlayerbyattribute-management-in/m-p/407949#M32147</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Xander Bakker hello, thanks for your response &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;but look, I made your sugerences and the code works in programs Python (PyScripter) but if I run in ArcToolbox scrpit of Arcgis Desktop not&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Attached a iamgenes of results from the study in the two cases: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1) with ArcToolbox scrpit of Arcgis Desktop&amp;nbsp; and I am print the error in the line select by atribute [ATTACH=CONFIG]31616[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2) with program PyScripter work well]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 20 Feb 2014 13:35:31 GMT</pubDate>
    <dc:creator>rafaelvargas</dc:creator>
    <dc:date>2014-02-20T13:35:31Z</dc:date>
    <item>
      <title>problem with SelectLayerByAttribute management in script</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-selectlayerbyattribute-management-in/m-p/407947#M32145</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;hello my problem is that this tool works perfectly in IDLE or PyScripter programs, but if I use in the script in ArcGIS desktop this problem occurs: arcgisscripting.ExecuteError:ERROR 000582...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;why not executing in Arcgis script and the other progran yes?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;the tool SelectLayerByAttribute management is inside the arcpy.da.UpdateCursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;this is my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy import datetime arcpy.env.overwriteOutput = True&amp;nbsp; territory= arcpy.GetParameterAsText(0) path= arcpy.GetParameterAsText(1) territory_lyr=&amp;nbsp; path+ "territorios_lyr"&amp;nbsp; arcpy.MakeFeatureLayer_management(territory,territory_lyr) fields= ("FID", "avg_mindis", "I_conc", "Max_lenght","TamanoTerr") with arcpy.da.UpdateCursor(territory,&amp;nbsp; fields) as cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; currentID= row[0] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where= "FID="+str(currentID) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(territory_lyr, "NEW_SELECTION",where)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Feb 2014 17:24:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-selectlayerbyattribute-management-in/m-p/407947#M32145</guid>
      <dc:creator>rafaelvargas</dc:creator>
      <dc:date>2014-02-19T17:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: problem with SelectLayerByAttribute management in script</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-selectlayerbyattribute-management-in/m-p/407948#M32146</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Rafael,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is the error message pointing to a specific line in the code? What is the exact content of the parameters?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I understand this correctly you create a feature layer and for each row you create a selection of that row, using the FID. I suppose there is more code which is not included in your post. What do you want to achieve with your code (what happens after the selection is created)?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A few pointers:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;UL&gt;&lt;BR /&gt;&lt;LI&gt;In your code you concatenate the path with a name "territorios_lyr". If your path is a true path,&amp;nbsp; the result will be missing the trailing slash at the end of the path. It is better to use &lt;SPAN style="font-family:courier new;"&gt;os.path.join(path, "territorios_lyr")&lt;/SPAN&gt; , this will require &lt;SPAN style="font-family:courier new;"&gt;import os&lt;/SPAN&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;However, when you create a feature layer, it resides in memory. You only specify a name (not a path) when creating the feature layer, so change the code to: &lt;SPAN style="font-family:courier new;"&gt;territory_lyr = "territorios_lyr"&lt;/SPAN&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;It is better to use "format" when combining text and numbers (for building the where clause): &lt;SPAN style="font-family:courier new;"&gt;where = "FID={0}".format(currentID)&lt;/SPAN&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Since the where clause depends on the type of data (with respect to field delimiters) and since the name of the FID column can be derived using arcpy.Describe, you could change it to:&lt;/LI&gt;&lt;BR /&gt;&lt;/UL&gt;&lt;PRE class="plain" name="code"&gt;fldFID = arcpy.Describe(territory).OIDFieldName fields= (fldFID, "avg_mindis", "I_conc", "Max_lenght","TamanoTerr") with arcpy.da.UpdateCursor(territory,&amp;nbsp; fields) as cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; currentID = row[0] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where = "{0}={1}".format(arcpy.AddFieldDelimiters(territory, fldFID), currentID) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(territory_lyr, "NEW_SELECTION", where) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # do something with the selection...&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kind regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Xander&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Feb 2014 05:21:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-selectlayerbyattribute-management-in/m-p/407948#M32146</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-02-20T05:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: problem with SelectLayerByAttribute management in script</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-selectlayerbyattribute-management-in/m-p/407949#M32147</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Xander Bakker hello, thanks for your response &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;but look, I made your sugerences and the code works in programs Python (PyScripter) but if I run in ArcToolbox scrpit of Arcgis Desktop not&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Attached a iamgenes of results from the study in the two cases: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1) with ArcToolbox scrpit of Arcgis Desktop&amp;nbsp; and I am print the error in the line select by atribute [ATTACH=CONFIG]31616[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2) with program PyScripter work well]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Feb 2014 13:35:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-selectlayerbyattribute-management-in/m-p/407949#M32147</guid>
      <dc:creator>rafaelvargas</dc:creator>
      <dc:date>2014-02-20T13:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: problem with SelectLayerByAttribute management in script</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-selectlayerbyattribute-management-in/m-p/407950#M32148</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;&lt;BLOCKQUOTE&gt;xander_bakker;367296 wrote:&lt;BR /&gt;Hi Rafael,....&lt;/BLOCKQUOTE&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Xander31619[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2) with program PyScripter work well [ATTACH=CONFIG]31618[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Feb 2014 13:43:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-selectlayerbyattribute-management-in/m-p/407950#M32148</guid>
      <dc:creator>rafaelvargas</dc:creator>
      <dc:date>2014-02-20T13:43:31Z</dc:date>
    </item>
  </channel>
</rss>

