<?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 memory leak in loop in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/loop-through-list-for-multivalue-input/m-p/480618#M37591</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I tried that, it's not the problem. I can watch the memory build up, once it gets to a certain threshhold it bombs out????&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 22 Jul 2011 16:15:37 GMT</pubDate>
    <dc:creator>RobertEhrman</dc:creator>
    <dc:date>2011-07-22T16:15:37Z</dc:date>
    <item>
      <title>Loop through list for multivalue input</title>
      <link>https://community.esri.com/t5/python-questions/loop-through-list-for-multivalue-input/m-p/480614#M37587</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a folder with hundreds of shapefiles each representing a diff. state, each file starts with the prefix for that specific state e.g., al001r.shp, al003r.shp, fl001.shp, fl003.shp...etc.&amp;nbsp; What I'm trying to do is Append the shapefiles for each state into one shapefile via python, in the end having a single shapefile for each state.&amp;nbsp; I'm thinking I need to create a list of each of the prefixes and enumerate through the list thus creating a list of inputs for a multivalue input for the append?&amp;nbsp; This is about as far as I've gotten, can't figure out how to select just the first iteration and push to a list for multi-input? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;dir = r"C:\temp"
gp.workspace = dir
print(dir)
files = os.listdir(dir)
alist = ['al', 'ct', 'dc', 'de', 'fl']
for file in files:
&amp;nbsp;&amp;nbsp;&amp;nbsp; sfile = file[0:2]
&amp;nbsp;&amp;nbsp;&amp;nbsp; if sfile in alist:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; alist[alist.index(sfile)] 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(sfile)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Jul 2011 13:32:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-through-list-for-multivalue-input/m-p/480614#M37587</guid>
      <dc:creator>RobertEhrman</dc:creator>
      <dc:date>2011-07-06T13:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through list for multivalue input</title>
      <link>https://community.esri.com/t5/python-questions/loop-through-list-for-multivalue-input/m-p/480615#M37588</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Below is an example on how to do this.&amp;nbsp; The code adds all the shapefiles first two characters to a list, then removes the duplicates.&amp;nbsp; It will then merge the related shapefiles together to one shapefile.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;lstFCs = arcpy.ListFeatureClasses("*")

list1 = []

# Append first two characters of each shapefile to list
for fc in lstFCs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; list1.append(fc[0:2])

# Remove duplicates from list
list1 = dict.fromkeys(list1)
list1 = list1.keys()

# Merge feature classes
for n in list1:
&amp;nbsp;&amp;nbsp;&amp;nbsp; m = str(n) + "*"
&amp;nbsp;&amp;nbsp;&amp;nbsp; lstFCs = arcpy.ListFeatureClasses(m)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Merge_management(lstFCs, n + "_merge")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:12:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-through-list-for-multivalue-input/m-p/480615#M37588</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T21:12:25Z</dc:date>
    </item>
    <item>
      <title>C++ Runtime Error</title>
      <link>https://community.esri.com/t5/python-questions/loop-through-list-for-multivalue-input/m-p/480616#M37589</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the suggestion, the code below ended up working....kind of.&amp;nbsp; There's over 800 files and the code works like a dream until it gets to the 417th file, then I get a C++ Runtime Error! for Program: pythonw.exe????&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt; Create the Geoprocessor object
gp = arcgisscripting.create(9.3)
dir = r"C:\temp"
output = r"C:\temp\shp"
gp.workspace = dir

fcs = gp.ListFeatureClasses("*")

x = '"%s"' % ';'.join(fcs)
print x
gp.Append(x, output, "NO_TEST")
print gp.getmessages()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:12:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-through-list-for-multivalue-input/m-p/480616#M37589</guid>
      <dc:creator>RobertEhrman</dc:creator>
      <dc:date>2021-12-11T21:12:28Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through list for multivalue input</title>
      <link>https://community.esri.com/t5/python-questions/loop-through-list-for-multivalue-input/m-p/480617#M37590</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try removing the 417th file and then re-execute the script to see if it works.&amp;nbsp; The file may be corrupted.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jul 2011 18:30:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-through-list-for-multivalue-input/m-p/480617#M37590</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2011-07-18T18:30:45Z</dc:date>
    </item>
    <item>
      <title>memory leak in loop</title>
      <link>https://community.esri.com/t5/python-questions/loop-through-list-for-multivalue-input/m-p/480618#M37591</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I tried that, it's not the problem. I can watch the memory build up, once it gets to a certain threshhold it bombs out????&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Jul 2011 16:15:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-through-list-for-multivalue-input/m-p/480618#M37591</guid>
      <dc:creator>RobertEhrman</dc:creator>
      <dc:date>2011-07-22T16:15:37Z</dc:date>
    </item>
  </channel>
</rss>

