<?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: How to make code loop instead of running with specific files one at a time in Python Snippets Questions</title>
    <link>https://community.esri.com/t5/python-snippets-questions/how-to-make-code-loop-instead-of-running-with/m-p/864294#M620</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about you use the &lt;A _jive_internal="true" href="https://community.esri.com/blogs/dan_patterson/2016/08/14/script-formatting"&gt;syntax highlighter&lt;/A&gt; so we can read your script easier?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 28 Aug 2020 15:49:54 GMT</pubDate>
    <dc:creator>JoeBorgione</dc:creator>
    <dc:date>2020-08-28T15:49:54Z</dc:date>
    <item>
      <title>How to make code loop instead of running with specific files one at a time</title>
      <link>https://community.esri.com/t5/python-snippets-questions/how-to-make-code-loop-instead-of-running-with/m-p/864293#M619</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Everyone: I have this code that works:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if not hasattr(sys, 'argv'): #only use if system has issue with relpath command&lt;BR /&gt; sys.argv = ['']&lt;/P&gt;&lt;P&gt;import arcpy, os, sys, locale&lt;/P&gt;&lt;P&gt;relpath = os.path.dirname(sys.argv[0])&lt;BR /&gt;p = arcpy.mp.ArcGISProject(relpath + r'C:/Users/ggrodzinsky/Documents/ArcGIS/Projects/MyProject8/MyProject8.aprx')&lt;BR /&gt;m = p.listMaps()[0]&lt;BR /&gt;l = m.listLayers("cb_2018_us_county_500k")[0]&lt;BR /&gt;sym = l.symbology&lt;BR /&gt;if hasattr(sym, 'renderer'):&lt;BR /&gt; if sym.renderer.type == 'SimpleRenderer':&lt;BR /&gt; sym.updateRenderer('GraduatedColorsRenderer')&lt;/P&gt;&lt;P&gt;l.symbology = sym&lt;/P&gt;&lt;P&gt;sym.renderer.classificationField = 'Sheet4.AWATER'&lt;BR /&gt;sym.renderer.breakCount = 7 &lt;BR /&gt; &lt;BR /&gt;breakVal = 1000&lt;BR /&gt;cv = 0&lt;BR /&gt;lw = 1&lt;BR /&gt;for brk in sym.renderer.classBreaks:&lt;BR /&gt; brk.upperBound = breakVal&lt;BR /&gt; brk.label = "\u2264" + str(locale.format("%d", breakVal, grouping=True))&lt;BR /&gt; brk.description = "Description " + str(cv)&lt;BR /&gt; brk.symbol.color = {'HSV' : [cv, 100, 100, 100]}&lt;BR /&gt; brk.symbol.outlineColor = {'HSV' : [240-cv, 100, 100, 100]}&lt;BR /&gt; brk.symbol.size = lw&lt;BR /&gt; breakVal +=1000&lt;BR /&gt; cv += 40&lt;BR /&gt; lw += 0.5&lt;BR /&gt;l.symbology = sym&lt;BR /&gt;p.saveACopy(relpath + r'C:/Users/ggrodzinsky/Documents/ArcGIS/Projects/MyProject8/SavedOutput2.aprx')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, I want to run it so it creates multiple maps in one efficient, condensed code with a loop instead of a lengthy code where within the code I repeat all the above and just change "AWATER" to the next column in my table and "SavedOutput2.aprx" to "SavedOutput3.aprx" to produced a series of symbolized maps. In short, how can I modify this code so the "&lt;SPAN&gt;sym.renderer.classificationField = 'Sheet4.AWATER' can be modified to allow for a loop where "AWATER" is replaced with a variable that with each loop grabs from the next column in the table. Same goes with the line:&amp;nbsp; p.saveACopy(relpath + r'C:/Users/ggrodzinsky/Documents/ArcGIS/Projects/MyProject8/SavedOutput2.aprx') where instead of "SavedOutput2.aprx" it is "SavedOutput#.aprx" where # is increased by one with each step in the loop, thus making a new file with each mapped column.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;GG&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Aug 2020 15:44:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/how-to-make-code-loop-instead-of-running-with/m-p/864293#M619</guid>
      <dc:creator>GilGrodzinsky</dc:creator>
      <dc:date>2020-08-28T15:44:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to make code loop instead of running with specific files one at a time</title>
      <link>https://community.esri.com/t5/python-snippets-questions/how-to-make-code-loop-instead-of-running-with/m-p/864294#M620</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about you use the &lt;A _jive_internal="true" href="https://community.esri.com/blogs/dan_patterson/2016/08/14/script-formatting"&gt;syntax highlighter&lt;/A&gt; so we can read your script easier?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Aug 2020 15:49:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/how-to-make-code-loop-instead-of-running-with/m-p/864294#M620</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2020-08-28T15:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to make code loop instead of running with specific files one at a time</title>
      <link>https://community.esri.com/t5/python-snippets-questions/how-to-make-code-loop-instead-of-running-with/m-p/864295#M621</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;&lt;CODE&gt; 
 

&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;not&lt;/SPAN&gt; hasattr&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;sys&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'argv'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;#only use if system has issue with relpath command&lt;/SPAN&gt;
sys&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;argv &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;''&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; os&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; sys&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; locale

relpath &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;dirname&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;sys&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;argv&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
p &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ArcGISProject&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;relpath &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'C:/Users/ggrodzinsky/Documents/ArcGIS/Projects/MyProject8/MyProject8.aprx'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
m &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; p&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;listMaps&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
l &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; m&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;listLayers&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"cb_2018_us_county_500k"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
sym &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; l&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;symbology
&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; hasattr&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;sym&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'renderer'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; sym&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;renderer&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;type &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'SimpleRenderer'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
sym&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;updateRenderer&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'GraduatedColorsRenderer'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

l&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;symbology &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; sym

sym&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;renderer&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;classificationField &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Sheet4.AWATER'&lt;/SPAN&gt;
sym&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;renderer&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;breakCount &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;7&lt;/SPAN&gt;

breakVal &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1000&lt;/SPAN&gt;
cv &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;
lw &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; brk &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; sym&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;renderer&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;classBreaks&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
brk&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;upperBound &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; breakVal
brk&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;label &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"\u2264"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;locale&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"%d"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; breakVal&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; grouping&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
brk&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;description &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Description "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;cv&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
brk&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;symbol&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;color &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'HSV'&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;cv&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;100&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;100&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;100&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
brk&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;symbol&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;outlineColor &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'HSV'&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;240&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;cv&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;100&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;100&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;100&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
brk&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;symbol&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;size &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; lw
breakVal &lt;SPAN class="operator token"&gt;+=&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1000&lt;/SPAN&gt;
cv &lt;SPAN class="operator token"&gt;+=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;40&lt;/SPAN&gt;
lw &lt;SPAN class="operator token"&gt;+=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0.5&lt;/SPAN&gt;
l&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;symbology &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; sym
p&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;saveACopy&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;relpath &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'C:/Users/ggrodzinsky/Documents/ArcGIS/Projects/MyProject8/SavedOutput2.aprx'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

 
 

 

 ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 10:44:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/how-to-make-code-loop-instead-of-running-with/m-p/864295#M621</guid>
      <dc:creator>GilGrodzinsky</dc:creator>
      <dc:date>2021-12-12T10:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to make code loop instead of running with specific files one at a time</title>
      <link>https://community.esri.com/t5/python-snippets-questions/how-to-make-code-loop-instead-of-running-with/m-p/864296#M622</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not completely sure of your data structure, but guessing from the code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Get a list of all your fields in USCounty500k (referencing the datasource not the layer - you could also get the datasource from the layer object if that's an issue) example courtesy of esri help:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;fields &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ListFields&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"c:/data/municipal.gdb/hospitals"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;


    &lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;indent your current code from line 19:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for field in fields:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; your remaining code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="display: inline !important; float: none; background-color: #f5f2f0; color: #000000; font-family: monospace; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: pre; word-spacing: 0px;"&gt;sym&lt;/SPAN&gt;&lt;SPAN style="border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; color: #999999; font-family: inherit; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; outline-color: invert; outline-style: none; outline-width: 0px; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; vertical-align: baseline; -webkit-text-stroke-width: 0px; white-space: pre; word-spacing: 0px; padding: 0px; margin: 0px; border: 0px none currentColor;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #f5f2f0; color: #000000; font-family: monospace; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: pre; word-spacing: 0px;"&gt;renderer&lt;/SPAN&gt;&lt;SPAN style="border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; color: #999999; font-family: inherit; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; outline-color: invert; outline-style: none; outline-width: 0px; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; vertical-align: baseline; -webkit-text-stroke-width: 0px; white-space: pre; word-spacing: 0px; padding: 0px; margin: 0px; border: 0px none currentColor;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #f5f2f0; color: #000000; font-family: monospace; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: pre; word-spacing: 0px;"&gt;classificationField &lt;/SPAN&gt;&lt;SPAN style="background-attachment: scroll; background-clip: border-box; background-color: rgba(255, 255, 255, 0.5); background-image: none; background-origin: padding-box; background-position-x: 0%; background-position-y: 0%; background-repeat: repeat; background-size: auto; border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; color: #a67f59; font-family: inherit; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; outline-color: invert; outline-style: none; outline-width: 0px; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; vertical-align: baseline; -webkit-text-stroke-width: 0px; white-space: pre; word-spacing: 0px; padding: 0px; margin: 0px; border: 0px none currentColor;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #f5f2f0; color: #000000; font-family: monospace; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: pre; word-spacing: 0px;"&gt; &lt;/SPAN&gt;&lt;SPAN style="border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; color: #669900; font-family: inherit; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; outline-color: invert; outline-style: none; outline-width: 0px; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; vertical-align: baseline; -webkit-text-stroke-width: 0px; white-space: pre; word-spacing: 0px; padding: 0px; margin: 0px; border: 0px none currentColor;"&gt;field.name&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;outpath_folder = &lt;SPAN style="display: inline !important; float: none; background-color: #f5f2f0; color: #000000; font-family: monospace; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: pre; word-spacing: 0px;"&gt;r&lt;/SPAN&gt;&lt;SPAN style="border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; color: #669900; font-family: inherit; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; outline-color: invert; outline-style: none; outline-width: 0px; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; vertical-align: baseline; -webkit-text-stroke-width: 0px; white-space: pre; word-spacing: 0px; padding: 0px; margin: 0px; border: 0px none currentColor;"&gt;'C:/Users/ggrodzinsky/Documents/ArcGIS/Projects/MyProject8'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #f5f2f0; color: #000000; font-family: monospace; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: pre; word-spacing: 0px;"&gt;p&lt;/SPAN&gt;&lt;SPAN style="border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; color: #999999; font-family: inherit; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; outline-color: invert; outline-style: none; outline-width: 0px; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; vertical-align: baseline; -webkit-text-stroke-width: 0px; white-space: pre; word-spacing: 0px; padding: 0px; margin: 0px; border: 0px none currentColor;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #f5f2f0; color: #000000; font-family: monospace; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: pre; word-spacing: 0px;"&gt;saveACopy&lt;/SPAN&gt;&lt;SPAN style="border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; color: #999999; font-family: inherit; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; outline-color: invert; outline-style: none; outline-width: 0px; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; vertical-align: baseline; -webkit-text-stroke-width: 0px; white-space: pre; word-spacing: 0px; padding: 0px; margin: 0px; border: 0px none currentColor;"&gt;(os.path.join(outpath_folder, field.name))&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 10:44:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/how-to-make-code-loop-instead-of-running-with/m-p/864296#M622</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-12-12T10:44:08Z</dc:date>
    </item>
  </channel>
</rss>

