<?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: Select By Attribute with Variable in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/select-by-attribute-with-variable/m-p/1053656#M60984</link>
    <description>&lt;P&gt;Of course you could always just use&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/analysis/split-by-attributes.htm" target="_blank"&gt;Split By Attributes (Analysis)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 03 May 2021 01:39:30 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2021-05-03T01:39:30Z</dc:date>
    <item>
      <title>Select By Attribute with Variable</title>
      <link>https://community.esri.com/t5/python-questions/select-by-attribute-with-variable/m-p/1053641#M60982</link>
      <description>&lt;P&gt;I'm trying to iterate through a shapefile with all of the roads in the State of Maine, select only the roads in towns relevant to my project, and then create one new feature class with just those roads. I'm working in Python in a Jupyter notebook and I'm a beginner in both Python and ArcGIS. This code runs, but selects all of the roads, not just those in the town list.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Create town list
town_list = ['Bangor','Hampden','Veazie','Orono','Brewer','Old Town']

arcpy.env.overwriteOutput = True
for town in town_list:
    select = """TOWN = '{}'""".format(town)
    arcpy.SelectLayerByAttribute_management(ME_roads,'NEW_SELECTION',select)
    arcpy.CopyFeatures_management(ME_roads,relevant_roads)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 02 May 2021 21:46:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-attribute-with-variable/m-p/1053641#M60982</guid>
      <dc:creator>ebrown</dc:creator>
      <dc:date>2021-05-02T21:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: Select By Attribute with Variable</title>
      <link>https://community.esri.com/t5/python-questions/select-by-attribute-with-variable/m-p/1053647#M60983</link>
      <description>&lt;P&gt;I'd say there's a few too many quotes in select:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;select = "TOWN = '{}'".format(town)&lt;/LI-CODE&gt;&lt;P&gt;Have you also made it a feature layer to run it on?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 02 May 2021 23:16:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-attribute-with-variable/m-p/1053647#M60983</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-05-02T23:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: Select By Attribute with Variable</title>
      <link>https://community.esri.com/t5/python-questions/select-by-attribute-with-variable/m-p/1053656#M60984</link>
      <description>&lt;P&gt;Of course you could always just use&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/analysis/split-by-attributes.htm" target="_blank"&gt;Split By Attributes (Analysis)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 01:39:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-attribute-with-variable/m-p/1053656#M60984</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-05-03T01:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: Select By Attribute with Variable</title>
      <link>https://community.esri.com/t5/python-questions/select-by-attribute-with-variable/m-p/1053773#M60996</link>
      <description>&lt;P&gt;From another set of eyes; I like &lt;A href="https://realpython.com/python-f-strings/" target="_self"&gt;f strings over the format()&lt;/A&gt; function if you are using Python 3.x:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;select = f'TOWN = {town}'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I too wondered what&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/167692"&gt;@DavidPike&lt;/a&gt;&amp;nbsp;mentioned about a feature layer...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 14:20:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-attribute-with-variable/m-p/1053773#M60996</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-05-03T14:20:39Z</dc:date>
    </item>
  </channel>
</rss>

