<?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: Still having problems stepping through a list inside of a tool in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292705#M22643</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Looks like that may be a step in the right direction.&amp;nbsp; However when I run the script with the recommended changes it is now selecting all features and also giving me the following error: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &amp;lt;type 'exceptions.AttributeError'&amp;gt;: PageLayoutObject: Error in executing ExportToJPEG&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;With the suggested changes here is how the code looks: &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Script to create distribution maps for wetland species
#Import arcpy and set workspace
import arcpy
import arcpy.mapping
arcpy.env.workspace = r"P:\CoWetlandTools\maps\distribution_maps_Johns_pytest"
import arcpy.sa
#generate a list
speciesList =("Achillea_millefolium", "Acroptilon_repens", "Actinea_osterhoutii")

#Create Loop and List to run processing for
for species in speciesList:

&amp;nbsp; #select counties each species is known to occur&amp;nbsp; 
&amp;nbsp; arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "NEW_SELECTION", " ' " + species + " ' &amp;gt; '0'")

&amp;nbsp; #Export selected to jpeg
&amp;nbsp; mxd = arcpy.mapping.MapDocument(r"CURRENT")
&amp;nbsp; 
&amp;nbsp; arcpy.mapping.ExportToJPEG(mxd, r"P:\CoWetlandTools\maps\" + species " + ".jpg")

&amp;nbsp; #clear selected attributes
&amp;nbsp; arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "CLEAR_SELECTION")

#finished
print "Finished"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I added another double quote to the ExportToJPEG function because I received a parsing error when testing the script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any thought on why it is selecting all features and not just the desired features?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 14:04:47 GMT</pubDate>
    <dc:creator>JohnNunnali</dc:creator>
    <dc:date>2021-12-11T14:04:47Z</dc:date>
    <item>
      <title>Still having problems stepping through a list inside of a tool</title>
      <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292703#M22641</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I had started a thread about a month ago on this same topic but want to start again at the beginning.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am attempting to iterate through a list inside of the SelectLayerByAttributes tool in ArcPy.&amp;nbsp; My goal is to be able to select attributes from a field (column), export the current map view with the selected attributes as a jpeg, clear the selection, and then start the process again for a different field.&amp;nbsp; I am currently trying to run all three steps within a loop.&amp;nbsp; My issue is that I can not figure out how to make the SelectLayerByAttributes tool step to the next field name after the first completes.&amp;nbsp; Currently the loop runs but just keeps selecting the values from the initial field and not changing to the next in the list.&amp;nbsp; I have attached an example of how the data is setup.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to select for values greater than zero for each column, then export the results, clear the selection, and them move to next column.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code currently looks like this: &lt;/SPAN&gt;&lt;PRE class="plain" name="code"&gt;#Script to create distribution maps for wetland species
#Import arcpy and set workspace
import arcpy
import arcpy.mapping
arcpy.env.workspace = r"P:\CoWetlandTools\maps\distribution_maps_Johns_pytest"
import arcpy.sa
#generate a list
speciesList =("Achillea_millefolium", "Acroptilon_repens", "Actinea_osterhoutii")

#Create Loop and List to run processing for
for species in speciesList:

&amp;nbsp; #select counties each species is known to occur&amp;nbsp; 
&amp;nbsp; arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "NEW_SELECTION", "'Achillea_milefolium' &amp;gt; '0'")

&amp;nbsp; #Export selected to jpeg
&amp;nbsp; mxd = arcpy.mapping.MapDocument(r"CURRENT")
&amp;nbsp; 
&amp;nbsp; arcpy.mapping.ExportToJPEG(mxd, r"P:\CoWetlandTools\maps\Achillea_milefolium.jpg")

&amp;nbsp; #clear selected attributes
&amp;nbsp; arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "CLEAR_SELECTION")

#finished
print "Finished"&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Where I need help is in the where clause of the arcpy.SelectLayerByAttribute_management function and the arcpy.mapping.ExportToJPEG function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any suggestions are greatly appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2012 19:14:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292703#M22641</guid>
      <dc:creator>JohnNunnali</dc:creator>
      <dc:date>2012-04-05T19:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems stepping through a list inside of a tool</title>
      <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292704#M22642</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You need to feed in the variable (species) value.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for species in speciesList:

&amp;nbsp; #select counties each species is known to occur&amp;nbsp; 
&amp;nbsp; arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "NEW_SELECTION", " ' " + species + " ' &amp;gt; '0'")
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;and...&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.mapping.ExportToJPEG(mxd, r"P:\CoWetlandTools\maps\" + species + ".jpg")
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:04:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292704#M22642</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T14:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems stepping through a list inside of a tool</title>
      <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292705#M22643</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Looks like that may be a step in the right direction.&amp;nbsp; However when I run the script with the recommended changes it is now selecting all features and also giving me the following error: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &amp;lt;type 'exceptions.AttributeError'&amp;gt;: PageLayoutObject: Error in executing ExportToJPEG&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;With the suggested changes here is how the code looks: &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Script to create distribution maps for wetland species
#Import arcpy and set workspace
import arcpy
import arcpy.mapping
arcpy.env.workspace = r"P:\CoWetlandTools\maps\distribution_maps_Johns_pytest"
import arcpy.sa
#generate a list
speciesList =("Achillea_millefolium", "Acroptilon_repens", "Actinea_osterhoutii")

#Create Loop and List to run processing for
for species in speciesList:

&amp;nbsp; #select counties each species is known to occur&amp;nbsp; 
&amp;nbsp; arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "NEW_SELECTION", " ' " + species + " ' &amp;gt; '0'")

&amp;nbsp; #Export selected to jpeg
&amp;nbsp; mxd = arcpy.mapping.MapDocument(r"CURRENT")
&amp;nbsp; 
&amp;nbsp; arcpy.mapping.ExportToJPEG(mxd, r"P:\CoWetlandTools\maps\" + species " + ".jpg")

&amp;nbsp; #clear selected attributes
&amp;nbsp; arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "CLEAR_SELECTION")

#finished
print "Finished"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I added another double quote to the ExportToJPEG function because I received a parsing error when testing the script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any thought on why it is selecting all features and not just the desired features?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:04:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292705#M22643</guid>
      <dc:creator>JohnNunnali</dc:creator>
      <dc:date>2021-12-11T14:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems stepping through a list inside of a tool</title>
      <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292706#M22644</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Numbers don't get quotes in SQL. And we had the quotes wrong anyways: field name gets double quotes, the whole thing is in single quotes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "NEW_SELECTION", ' " ' + species + ' " &amp;gt; 0')&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm pretty sure this is right (you have to have an even number of matching quotes):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.mapping.ExportToJPEG(mxd, r"P:\CoWetlandTools\maps\" + species + ".jpg")
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:04:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292706#M22644</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T14:04:49Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems stepping through a list inside of a tool</title>
      <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292707#M22645</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This time I received the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &amp;lt;class 'arcgisscripting.ExecuteError'&amp;gt;: ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute). &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Script to create distribution maps for wetland species
#Import arcpy and set workspace
import arcpy
import arcpy.mapping
arcpy.env.workspace = r"P:\CoWetlandTools\maps\distribution_maps_Johns_pytest"
import arcpy.sa
#generate a list
speciesList =("Achillea_millefolium", "Acroptilon_repens", "Actinea_osterhoutii")

#Create Loop and List to run processing for
for species in speciesList:

&amp;nbsp; #select counties each species is known to occur&amp;nbsp; 
&amp;nbsp; arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "NEW_SELECTION", ' " ' + species + ' " &amp;gt; 0')

&amp;nbsp; #Export selected to jpeg
&amp;nbsp; mxd = arcpy.mapping.MapDocument(r"CURRENT")
&amp;nbsp; 
&amp;nbsp; arcpy.mapping.ExportToJPEG(mxd, r"P:\CoWetlandTools\maps\' + species + '.jpg")

&amp;nbsp; #clear selected attributes
&amp;nbsp; arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "CLEAR_SELECTION")

#finished
print "Finished"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Should I be using &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "NEW_SELECTION", ' " ' + speciesList + ' " &amp;gt; 0')&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;instead?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Never mind.&amp;nbsp; Can't concatenate str and list or str and tuple objects.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:04:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292707#M22645</guid>
      <dc:creator>JohnNunnali</dc:creator>
      <dc:date>2021-12-11T14:04:52Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems stepping through a list inside of a tool</title>
      <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292708#M22646</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;What kind of file are you trying to select from? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Your workspace is set to: "P:\CoWetlandTools\maps\distribution_maps_Johns_pytest"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The file is: "counties_edited_datamergetest"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...which amounts to a file called "P:\CoWetlandTools\maps\distribution_maps_Johns_pytest\counties_edited_datamergetest"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...which is not any sort of feature class I know of.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If it's inside a geodatabase, that should be in your workspace (e.g. "P:\CoWetlandTools\maps\distribution_maps_Johns_pytest.gdb" if that's what it's called).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If it's a shapefile, that should be in the file name (e.g. "counties_edited_datamergetest.shp").&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2012 20:30:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292708#M22646</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2012-04-05T20:30:47Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems stepping through a list inside of a tool</title>
      <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292709#M22647</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm selecting from a shapefile in an mxd.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried adding .shp to the file name but get the following runtime error which I did not encounter before.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &amp;lt;class 'arcgisscripting.ExecuteError'&amp;gt;: ERROR 000732: Layer Name or Table View: Dataset counties_edited_datamergetest.shp does not exist or is not supported &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think the function is written to locate a layer name or table view as it appears in the environment that you set as the workspace.&amp;nbsp; When testing the process for a single species I did not encounter any problems with data paths.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2012 20:43:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292709#M22647</guid>
      <dc:creator>JohnNunnali</dc:creator>
      <dc:date>2012-04-05T20:43:29Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems stepping through a list inside of a tool</title>
      <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292710#M22648</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Are the fields actually numeric (integer, float, double) or text? You can check in the field properties. They should be a numeric data type.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, try putting "print species" (no quotes) as the first line in your loop just to make sure it's bringing in the right name.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2012 20:53:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292710#M22648</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2012-04-05T20:53:52Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems stepping through a list inside of a tool</title>
      <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292711#M22649</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The field types are "double".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I added print species as the first line of the loop and it returned&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Achillea_millefolim&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;so it appears it is bringing them in correctly.&amp;nbsp; I am still getting the following error message:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &amp;lt;class 'arcgisscripting.ExecuteError'&amp;gt;: ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute). &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My current code looks like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Script to create distribution maps for wetland species
#Import arcpy and set workspace
import arcpy
import arcpy.mapping
arcpy.env.workspace = r"P:\CoWetlandTools\maps\distribution_maps_Johns_pytest.mxd"
import arcpy.sa
#generate a list
speciesList =("Achillea_millefolium", "Acroptilon_repens", "Actinea_osterhoutii")
species = ' ' in speciesList

#Create Loop and List to run processing for
for species in speciesList:
&amp;nbsp; print species&amp;nbsp;&amp;nbsp; 
&amp;nbsp; #select counties each species is known to occur&amp;nbsp; 
&amp;nbsp; arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "NEW_SELECTION", ' " ' + species + ' " &amp;gt; 0')

&amp;nbsp; #Export selected to jpeg
&amp;nbsp; mxd = arcpy.mapping.MapDocument(r"CURRENT")
&amp;nbsp; 
&amp;nbsp; arcpy.mapping.ExportToJPEG(mxd, r"P:\CoWetlandTools\maps\' + speciesList + '.jpg")

&amp;nbsp; #clear selected attributes
&amp;nbsp; arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "CLEAR_SELECTION")

#finished
print "Finished"
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:04:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292711#M22649</guid>
      <dc:creator>JohnNunnali</dc:creator>
      <dc:date>2021-12-11T14:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems stepping through a list inside of a tool</title>
      <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292712#M22650</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm almost positive your workspace can't be an mxd.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, this line needs to have matching quotes, and just "species", like so:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.mapping.ExportToJPEG(mxd, r"P:\CoWetlandTools\maps\" + species + ".jpg")
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:04:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292712#M22650</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T14:04:57Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems stepping through a list inside of a tool</title>
      <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292713#M22651</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try this for your select statement:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.SelectLayerByAttribute_management("counties_edited_datamergetest", "NEW_SELECTION",&amp;nbsp; "'" + str(species) + "' &amp;gt; 0&amp;nbsp; "&amp;nbsp; )
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:05:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292713#M22651</guid>
      <dc:creator>KevinHibma</dc:creator>
      <dc:date>2021-12-11T14:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems stepping through a list inside of a tool</title>
      <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292714#M22652</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hmmmm.....I was able to make it work for a single species.&amp;nbsp; I need to have the workspace as an mxd because I am exporting the "current" view with the attributes selected to a jpeg.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any suggestions?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2012 21:38:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292714#M22652</guid>
      <dc:creator>JohnNunnali</dc:creator>
      <dc:date>2012-04-05T21:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems stepping through a list inside of a tool</title>
      <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292715#M22653</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/422912"&gt;@Kevin&lt;/a&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried your code line and still received the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &amp;lt;class 'arcgisscripting.ExecuteError'&amp;gt;: ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute). &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is my current code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
#Script to create distribution maps for wetland species
#Import arcpy and set workspace
import arcpy
import arcpy.mapping
arcpy.env.workspace = r"P:\CoWetlandTools\maps\distribution_maps_Johns_pytest.mxd"
import arcpy.sa
#generate a list
speciesList =("Achillea_millefolium", "Acroptilon_repens", "Actinea_osterhoutii")


#Create Loop and List to run processing for
for species in speciesList:
&amp;nbsp; print species&amp;nbsp;&amp;nbsp; 
&amp;nbsp; #select counties each species is known to occur&amp;nbsp; 
&amp;nbsp; arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "NEW_SELECTION",&amp;nbsp; '"' + str(species) + '"&amp;nbsp; &amp;gt; 0')

&amp;nbsp; #Export selected to jpeg
&amp;nbsp; mxd = arcpy.mapping.MapDocument(r"CURRENT")
&amp;nbsp; 
&amp;nbsp; arcpy.mapping.ExportToJPEG(mxd, r"P:\CoWetlandTools\maps\"'" + str(species) + "'.jpg")

&amp;nbsp; #clear selected attributes
&amp;nbsp; arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "CLEAR_SELECTION")

#finished
print "Finished"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:05:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292715#M22653</guid>
      <dc:creator>JohnNunnali</dc:creator>
      <dc:date>2021-12-11T14:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems stepping through a list inside of a tool</title>
      <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292716#M22654</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try using this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "NEW_SELECTION", "\"%s\" &amp;gt; 0" % species)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Apr 2012 15:14:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292716#M22654</guid>
      <dc:creator>BruceNielsen</dc:creator>
      <dc:date>2012-04-06T15:14:39Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems stepping through a list inside of a tool</title>
      <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292717#M22655</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;@ Bruce&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried your suggestion but received the same error I received with the other formats:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &amp;lt;class 'arcgisscripting.ExecuteError'&amp;gt;: ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute). &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have re-worked my code some and I am now using arcpy.ListFields to define the fields I want to make the selections in.&amp;nbsp; I just can't seem to figure out the reason why the SQL expression in the SelectLayerByAttribute function is invalid.&amp;nbsp; I know that the field list is generating properly because when testing I was able to successfully print the desired field names.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any thoughts or suggestion are much appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my current code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Script to create distribution maps for wetland species
#Import arcpy and set workspace
import arcpy
import arcpy.mapping
arcpy.env.workspace = r"P:\CoWetlandTools\maps\distribution_maps_Johns_pytest.mxd"
import arcpy.sa


#list object that is the list of fields in our table
#List fields and generate a list

fields = arcpy.ListFields(r"Y:\John_N\Wetland_field_guide_distribution_maps\counties_edited_datamergetest_export.shp", None , "Double")


#select fieldname1 &amp;gt; 0

#Create Loop and List to run processing for
for field in fields:
&amp;nbsp; 
&amp;nbsp; #select counties each field has attribute values &amp;gt; 0
&amp;nbsp; #select field1 &amp;gt; 0
&amp;nbsp; arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "NEW_SELECTION",&amp;nbsp; "'" + str(field) + "'" ' &amp;gt; 0')

&amp;nbsp; # export current to jpg such that the name of the file is field1
&amp;nbsp; mxd = arcpy.mapping.MapDocument(r"CURRENT")
&amp;nbsp; 
&amp;nbsp; arcpy.mapping.ExportToJPEG(mxd, r"P:\CoWetlandTools\maps\"'" + str(field) + "'.jpg")

&amp;nbsp; #clear selected attributes
&amp;nbsp; arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "CLEAR_SELECTION")

#finished
print "Finished"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:05:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292717#M22655</guid>
      <dc:creator>JohnNunnali</dc:creator>
      <dc:date>2021-12-11T14:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems stepping through a list inside of a tool</title>
      <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292718#M22656</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have made a little progress.&amp;nbsp; I used pythonWin to debug the program and finally have more info on why the script is failing at the SelectLayerByAttribute step.&amp;nbsp; The error is as follows:&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 "C:\ESRI\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 309, in RunScript&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; debugger.run(codeObject, __main__.__dict__, start_stepping=0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\ESRI\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\debugger\__init__.py", line 60, in run&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\ESRI\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\debugger\debugger.py", line 624, in run&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; exec cmd in globals, locals&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "Y:\John_N\From_desktop\python_training_scripts\dist_map_test1.py", line 22, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management (r"Y:\John_N\Wetland_field_guide_distribution_maps\counties_datamergetest_export2.lyr", "NEW_SELECTION", '"' + str(field) + '" ' &amp;gt; 0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\ESRI\ArcGIS\Desktop10.0\arcpy\arcpy\management.py", line 4259, in SelectLayerByAttribute&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise e&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ExecuteError: Failed to execute. Parameters are not valid.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000825: The value is not a layer or table view&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000840: The value is not a Raster Layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000840: The value is not a Mosaic Layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (SelectLayerByAttribute).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I saved the shapefile I was using as a layer file and tried to use that path but receive the same error.&amp;nbsp; Am I missing something or incorrectly saving as a layer file?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Apr 2012 15:44:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292718#M22656</guid>
      <dc:creator>JohnNunnali</dc:creator>
      <dc:date>2012-04-11T15:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems stepping through a list inside of a tool</title>
      <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292719#M22657</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Your where statement must be entirely enclosed in single quotes. Your field name must be enclosed in double quotes. &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;' " ' + str(field) + ' " &amp;gt; 0 '&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, reference the layer in your map ("counties_edited_datamergetest"), not the .lyr file.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Apr 2012 15:53:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292719#M22657</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2012-04-11T15:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems stepping through a list inside of a tool</title>
      <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292720#M22658</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;OK, this problem was frustrating me so I actually tried it. Here's a copy that works for my mxd named "junk" and a file named "file". Change as appropriate.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
mxd = arcpy.mapping.MapDocument(r"H:\GIS_Data\junk.mxd")
fields = arcpy.ListFields(r"H:\GIS_Data\TEMP.gdb\file", None , "SmallInteger")
for field in fields:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd, "file", arcpy.mapping.ListDataFrames(mxd)[0]):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management (lyr, "NEW_SELECTION",&amp;nbsp; '"' + field.name + '" &amp;gt; 0')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToJPEG(mxd, r"H:\GIS_Data\map_" + field.name + ".jpg")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management (lyr, "CLEAR_SELECTION")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:05:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292720#M22658</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T14:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems stepping through a list inside of a tool</title>
      <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292721#M22659</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The last suggestion appears to solve the invalid expression issue I was having in the SelectLayerByAttribute function.&amp;nbsp; The script now returns no error messages when running it through the PythonWin debugger.&amp;nbsp; However when executing it no records are selected.&amp;nbsp; It appears it successfully reads all lines in the code because it prints "finished" however it seems to exit the loop without selecting any features.&amp;nbsp; The current code is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Script to create distribution maps for wetland species
#Import arcpy and set workspace
import arcpy
import arcpy.mapping
mxd = arcpy.mapping.MapDocument (r"P:\CoWetlandTools\maps\distribution_maps_Johns_pytest.mxd")

#list object that is the list of fields in our table
#List fields and generate a list

fields = arcpy.ListFields(r"Y:\John_N\Wetland_field_guide_distribution_maps\counties_datamerge.gdb\counties_edited_datamergetest" , None , "Double")

#select fieldname1 &amp;gt; 0

#Create Loop and List to run processing for
for field in fields:
&amp;nbsp; for lyr in arcpy.mapping.ListLayers (mxd, "file" , arcpy.mapping.ListDataFrames (mxd) [0]):
&amp;nbsp;&amp;nbsp;&amp;nbsp; #select counties each field has attribute values &amp;gt; 0
&amp;nbsp;&amp;nbsp;&amp;nbsp; #select field1 &amp;gt; 0
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management (lyr, "NEW_SELECTION", '"' + field.name + '"&amp;nbsp; &amp;gt; 0')

&amp;nbsp;&amp;nbsp;&amp;nbsp; # export current to jpg such that the name of the file is field1
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToJPEG(mxd, r"P:\CoWetlandTools\maps\map_ " + field.name + ".jpg")

&amp;nbsp;&amp;nbsp;&amp;nbsp; #clear selected attributes
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management (lyr, "CLEAR_SELECTION")

#finished
print "Finished"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried with the data in a shapefile and a personal geodatabase with similar results.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All suggestions are greatly appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:05:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292721#M22659</guid>
      <dc:creator>JohnNunnali</dc:creator>
      <dc:date>2021-12-11T14:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems stepping through a list inside of a tool</title>
      <link>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292722#M22660</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for lyr in arcpy.mapping.ListLayers (mxd, "file" , arcpy.mapping.ListDataFrames (mxd) [0]):
&lt;/PRE&gt;&lt;SPAN&gt;The above line means, "list all of the layers named 'file' from the first data frame in the map, 'mxd' ". Change 'file' to be the name of your layer in the map.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:05:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/still-having-problems-stepping-through-a-list/m-p/292722#M22660</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T14:05:14Z</dc:date>
    </item>
  </channel>
</rss>

