<?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: Can you query a variable in Select_analyis? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/can-you-query-a-variable-in-select-analyis/m-p/518038#M40590</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, Boom is the variable I would like to pass. It would increase with each iteration ideally, effectively exporting each feature as it's own shapefile.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 07 Jun 2012 14:03:50 GMT</pubDate>
    <dc:creator>LeeEllenburg</dc:creator>
    <dc:date>2012-06-07T14:03:50Z</dc:date>
    <item>
      <title>Can you query a variable in Select_analyis?</title>
      <link>https://community.esri.com/t5/python-questions/can-you-query-a-variable-in-select-analyis/m-p/518036#M40588</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;I an having troubles querying a variable using the arcpy.Select_analysis() tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy from arcpy import env&amp;nbsp;&amp;nbsp; env.workspace = "D:\\Lee\\IrrigationProject"&amp;nbsp; In = "boombuffer.shp" Out = "D:\\Lee\\IrrigationProject\\IrrigationModel\\BoomBuffers\\Boom" Boom = 1&amp;nbsp; arcpy.Select_analysis(In, Out + str(Boom) + ".shp" , '"BoomNumber" = 'Boom'')&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is not valid syntax, however I can't seem to figure it out. I would like to include this in a loop that would create a new shapefile from each feature in the input shapefile. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be greatly appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Jun 2012 21:30:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-you-query-a-variable-in-select-analyis/m-p/518036#M40588</guid>
      <dc:creator>LeeEllenburg</dc:creator>
      <dc:date>2012-06-06T21:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: Can you query a variable in Select_analyis?</title>
      <link>https://community.esri.com/t5/python-questions/can-you-query-a-variable-in-select-analyis/m-p/518037#M40589</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Something like this should work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;variable = "Boom"
field_name = "BoomNumber"
delim_field_name = arcpy.AddFieldDelimiters(env.workspace,field_name)
arcpy.Select_analysis(In, Out + str(Boom) + ".shp", "{0} = '{1}'".format(delim_field_name,variable)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Or maybe I didn't understand what you are trying to do. Is Boom your attribute or your variable you want to pass?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:36:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-you-query-a-variable-in-select-analyis/m-p/518037#M40589</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-11T22:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: Can you query a variable in Select_analyis?</title>
      <link>https://community.esri.com/t5/python-questions/can-you-query-a-variable-in-select-analyis/m-p/518038#M40590</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, Boom is the variable I would like to pass. It would increase with each iteration ideally, effectively exporting each feature as it's own shapefile.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jun 2012 14:03:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-you-query-a-variable-in-select-analyis/m-p/518038#M40590</guid>
      <dc:creator>LeeEllenburg</dc:creator>
      <dc:date>2012-06-07T14:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: Can you query a variable in Select_analyis?</title>
      <link>https://community.esri.com/t5/python-questions/can-you-query-a-variable-in-select-analyis/m-p/518039#M40591</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That sounds like you are trying to do a &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000800000006000000" rel="nofollow" target="_blank"&gt;Split&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you need more control than that, this should work. Assumes BoomNumber is a numeric value.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy from arcpy import env&amp;nbsp; env.workspace = "D:\\Lee\\IrrigationProject"&amp;nbsp; In = "boombuffer.shp" Out = "D:\\Lee\\IrrigationProject\\IrrigationModel\\BoomBuffers\\Boom"&amp;nbsp; boom_list = [] boom = None field_name = "BoomNumber" delim_field_name = arcpy.AddFieldDelimiters(env.workspace,field_name)&amp;nbsp; # Creates and runs cursor to add all unique values to a list s_curs = arcpy.SearchCursor(In) for s_row in s_curs: &amp;nbsp;&amp;nbsp;&amp;nbsp; add_val = s_row.getValue(field_name) &amp;nbsp;&amp;nbsp;&amp;nbsp; if add_val not in boom_list: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; boom_list.append(add_val)&amp;nbsp; # Loops through list of unique boom values and export each one to a new shapefile for boom in boom_list: &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Select_analysis(In, Out + str(boom) + ".shp", "{0} = {1}".format(delim_field_name,boom)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jun 2012 14:17:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-you-query-a-variable-in-select-analyis/m-p/518039#M40591</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-06-07T14:17:04Z</dc:date>
    </item>
    <item>
      <title>Re: Can you query a variable in Select_analyis?</title>
      <link>https://community.esri.com/t5/python-questions/can-you-query-a-variable-in-select-analyis/m-p/518040#M40592</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ahhh, yes. Split will work just fine! Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jun 2012 17:55:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-you-query-a-variable-in-select-analyis/m-p/518040#M40592</guid>
      <dc:creator>LeeEllenburg</dc:creator>
      <dc:date>2012-06-07T17:55:10Z</dc:date>
    </item>
  </channel>
</rss>

