<?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: create variable counter name from string functions and then auto-increment in loo in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/create-variable-counter-name-from-string-functions/m-p/37906#M2961</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Greetings All&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;After having a read of dictionaries, it seems the ideal solution in this instance. The code is clean and straightforward which I like.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;here's my list of feature classes:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;masterlist = "CoreTestLocation,CoverToReo,Defect_Areas"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;here's my dictionary:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;dcount = {'CoreTestLocation': 0, 'CoverToReo': 0, 'Defect_Areas': 0,}&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It gets the number of features:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fcrecs = int(arcpy.GetCount_management(fc).getOutput(0))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;here's where the fc variable (from ListFeatureClasses) checks to see if it lives in the masterlist. It then gets the current count for the relevant fc from the dictionary, updates it and then puts the new value back.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;if string.find(masterlist,fc) != -1:
[INDENT]print fc + " has " + str(fcrecs) + " features"
currentval = dcount[fc]
newval = currentval + fcrecs
dcount[fc] = newval
[/INDENT]
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the help&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 21:28:40 GMT</pubDate>
    <dc:creator>DustinEdge</dc:creator>
    <dc:date>2021-12-10T21:28:40Z</dc:date>
    <item>
      <title>create variable counter name from string functions and then auto-increment in loop</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-counter-name-from-string-functions/m-p/37901#M2956</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Greetings All&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;hopefully the subject makes sense and if not, here's a longer version:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have about 350 mdbs in various folders that have the same schemas and has data captured over 2 years.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;due to some reporting errors that have now come to light, i need to do a count/append on all the features and report on any discrepanies.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;i used the os.walk function to find all the mdbs and then used a check to make sure the source feature class had some features (getcount) and that it matched my blank target checking mdb. if it matched, it appends the data and moves on.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;i used a string variable to hold the master list of feature class names:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"defects,photos,building,etc"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;to check the source feature class existence, i used a simple string.find(fc, masterlist) != 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;while its easy to create a simple counter to return total number of records written, what i really want to do is have several counters, one for each feature class. and the counter gets called and incremented only when it encounters one of the feature classes with valid features. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Like: defects_count, photos_count, building_count etc&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;while its easy to build the variable name using string functions (varcounter = fc + "_count") I dont see how i could keep incrementing the number of features found using varcounter = varcounter + countfc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;is python smart enough to figure out that the string i created in a variable is actually another number variable?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Apologies for the long post&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks in advance&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Feb 2013 10:32:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-counter-name-from-string-functions/m-p/37901#M2956</guid>
      <dc:creator>DustinEdge</dc:creator>
      <dc:date>2013-02-13T10:32:50Z</dc:date>
    </item>
    <item>
      <title>Re: create variable counter name from string functions and then auto-increment in loo</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-counter-name-from-string-functions/m-p/37902#M2957</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'll just make a brief suggestion -&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You already have what I think you called a string variable of fc names for which you want the counts for, is that correct?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I suggest (with the above assumption) is that since the fc names are already essentially a list, why not set up a python dictionary of those fc names to use as a key and pair them with your index variable counters?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So how it works is when you 'encounter' as you said the valid features, all you have to do is look up the appropriate fc by name in the dictionary and increment the corresponding index (which should be integer type)...easier to track and all the indexes are in a convenient single place to fetch or report on them, say, at the completion of your script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Enjoy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Feb 2013 11:17:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-counter-name-from-string-functions/m-p/37902#M2957</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-02-13T11:17:29Z</dc:date>
    </item>
    <item>
      <title>Re: create variable counter name from string functions and then auto-increment in loo</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-counter-name-from-string-functions/m-p/37903#M2958</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Wayne&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I suppose I&amp;nbsp; could&amp;nbsp; add array instead of&amp;nbsp; string and add a second value to&amp;nbsp; item in the array. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will give it&amp;nbsp; shot and report back.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;cheers&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Feb 2013 18:58:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-counter-name-from-string-functions/m-p/37903#M2958</guid>
      <dc:creator>DustinEdge</dc:creator>
      <dc:date>2013-02-13T18:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: create variable counter name from string functions and then auto-increment in loo</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-counter-name-from-string-functions/m-p/37904#M2959</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes something like that...do what is comfortable for you.&amp;nbsp; Note that the functionality is mimicked using the 'dictionary' data structure - and this is native to Python and is fairly easy to use and well-documented, see:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://docs.python.org/2/tutorial/datastructures.html#dictionaries" rel="nofollow noopener noreferrer" target="_blank"&gt;http://docs.python.org/2/tutorial/datastructures.html#dictionaries&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't have a good ready example, but consider this monkeying within IDLE - I'm not suggested you use it quite this way, but this should give you an idea:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; fcNames = {}
&amp;gt;&amp;gt;&amp;gt; type(fcNames)
&amp;lt;type 'dict'&amp;gt;
&amp;gt;&amp;gt;&amp;gt; 
&amp;gt;&amp;gt;&amp;gt; fcNames['fc1'] = 3
&amp;gt;&amp;gt;&amp;gt; print fcNames
{'fc1': 3}
&amp;gt;&amp;gt;&amp;gt; 
&amp;gt;&amp;gt;&amp;gt; fcNames['fc1']
3
&amp;gt;&amp;gt;&amp;gt; 
&amp;gt;&amp;gt;&amp;gt; fcNames['fc2'] = 10
&amp;gt;&amp;gt;&amp;gt;
&amp;gt;&amp;gt;&amp;gt; fcNames
{'fc1': 3, 'fc2': 10}
&amp;gt;&amp;gt;&amp;gt;
&amp;gt;&amp;gt;&amp;gt; for i in range(10):
 i = fcNames['fc1']
 i += 1
 fcNames['fc1'] = i

 
&amp;gt;&amp;gt;&amp;gt; fcNames['fc1']
13
&amp;gt;&amp;gt;&amp;gt; fcNames
{'fc1': 13, 'fc2': 10}
&amp;gt;&amp;gt;&amp;gt; 
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps shed a tiny light on the subject.&amp;nbsp; I have used 'lists' a lot, and a little embarrassed to say I haven't used dictionaries that much at all - I'm sure others have much better examples...an array should work too; this is just the 'pythonic' way.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And I should use it more because I see a lot of examples - such as GetInstallInfo and serviceProperties on a Layer (if supported for the layer type).&amp;nbsp; Both return dictionary data types.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/GetInstallInfo/018v00000004000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#/GetInstallInfo/018v00000004000000/&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//00s300000008000000" rel="nofollow noopener noreferrer" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//00s300000008000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Enjoy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:28:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-counter-name-from-string-functions/m-p/37904#M2959</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-10T21:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: create variable counter name from string functions and then auto-increment in loo</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-counter-name-from-string-functions/m-p/37905#M2960</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Wayne has the right idea I think, incrementing a dict counter with fc name as the key would be fairly easy. You can be a little more concise than the posted example.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for i in range(10):
 fcNames['fc1'] += 1&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:28:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-counter-name-from-string-functions/m-p/37905#M2960</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-10T21:28:37Z</dc:date>
    </item>
    <item>
      <title>Re: create variable counter name from string functions and then auto-increment in loo</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-counter-name-from-string-functions/m-p/37906#M2961</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Greetings All&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;After having a read of dictionaries, it seems the ideal solution in this instance. The code is clean and straightforward which I like.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;here's my list of feature classes:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;masterlist = "CoreTestLocation,CoverToReo,Defect_Areas"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;here's my dictionary:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;dcount = {'CoreTestLocation': 0, 'CoverToReo': 0, 'Defect_Areas': 0,}&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It gets the number of features:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fcrecs = int(arcpy.GetCount_management(fc).getOutput(0))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;here's where the fc variable (from ListFeatureClasses) checks to see if it lives in the masterlist. It then gets the current count for the relevant fc from the dictionary, updates it and then puts the new value back.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;if string.find(masterlist,fc) != -1:
[INDENT]print fc + " has " + str(fcrecs) + " features"
currentval = dcount[fc]
newval = currentval + fcrecs
dcount[fc] = newval
[/INDENT]
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the help&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:28:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-counter-name-from-string-functions/m-p/37906#M2961</guid>
      <dc:creator>DustinEdge</dc:creator>
      <dc:date>2021-12-10T21:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: create variable counter name from string functions and then auto-increment in loo</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-counter-name-from-string-functions/m-p/37907#M2962</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I would make a few minor changes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If your list is coming in as a string for whatever reason you can just do this to make it an actual list.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;masterlist = masterlist.split(',')&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Then in your loop you can just do this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;if fc in masterlist:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print('{0} has {1} features'.format(fc, fcrecs))
&amp;nbsp;&amp;nbsp;&amp;nbsp; dcount[fc] += fcrecs&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:28:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-counter-name-from-string-functions/m-p/37907#M2962</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-10T21:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: create variable counter name from string functions and then auto-increment in loo</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-counter-name-from-string-functions/m-p/37908#M2963</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey Mathew&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;that would be the better way, but I'm not 100% sure that somewhere along the way someone has introduced another featureclass or edited a featureclass's name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;By using the if statement I can catch featureclasses that dont meet the masterlist criteria.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Feb 2013 00:46:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-counter-name-from-string-functions/m-p/37908#M2963</guid>
      <dc:creator>DustinEdge</dc:creator>
      <dc:date>2013-02-14T00:46:03Z</dc:date>
    </item>
    <item>
      <title>Re: create variable counter name from string functions and then auto-increment in loo</title>
      <link>https://community.esri.com/t5/python-questions/create-variable-counter-name-from-string-functions/m-p/37909#M2964</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dictionaries are definitely the way to go.&amp;nbsp; Little confusing at first, but I promise you'll be better off after its all said and done.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Feb 2013 12:54:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-variable-counter-name-from-string-functions/m-p/37909#M2964</guid>
      <dc:creator>ShaunCavey</dc:creator>
      <dc:date>2013-02-19T12:54:21Z</dc:date>
    </item>
  </channel>
</rss>

