<?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: Sequential field calculation with Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/sequential-field-calculation-with-python/m-p/231#M68</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is the solution!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use the original script to sequentially order.&amp;nbsp; After that is done field calculate again using the field you wish to add the extra digits to.&amp;nbsp; Then you can choose the string type as .zfill and add as many zeros as you would like.&amp;nbsp; I attached a screen shot to help clarify.&amp;nbsp; This gave me the result I was looking for!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Python.jpg" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/206506_Python.jpg" style="height: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 01 Jun 2016 15:25:57 GMT</pubDate>
    <dc:creator>KatyW</dc:creator>
    <dc:date>2016-06-01T15:25:57Z</dc:date>
    <item>
      <title>Sequential field calculation with Python</title>
      <link>https://community.esri.com/t5/python-questions/sequential-field-calculation-with-python/m-p/228#M65</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;I'm trying to field calculate some records that have a null value.&amp;nbsp; I used the following code from the ESRI help section on sequential calculations.&amp;nbsp; It worked!&amp;nbsp; Now I need to modify the script a bit.&amp;nbsp; This code gives me a sequential order of single digits.&amp;nbsp; I would like to have some zeros before the new assigned digit.&amp;nbsp; 0001 instead of just 1.&amp;nbsp; How do I add the three zeros before the assigned digit?&amp;nbsp; I would like a four digit value in the end.&amp;nbsp; 0001, 0002, 0003, etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's the python code I used:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Parser:&lt;/P&gt;&lt;P&gt;Python&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Expression:&lt;/P&gt;&lt;P&gt;autoIncrement()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code Block:&lt;/P&gt;&lt;P&gt;rec=0&lt;/P&gt;&lt;P&gt;def autoIncrement():&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; global rec&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pStart = 1 #adjust start value, if req'd &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pInterval = 1 #adjust interval value, if req'd&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (rec == 0): &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rec = pStart &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else: &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rec = rec + pInterval &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return rec&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Jun 2016 14:35:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sequential-field-calculation-with-python/m-p/228#M65</guid>
      <dc:creator>KatyW</dc:creator>
      <dc:date>2016-06-01T14:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: Sequential field calculation with Python</title>
      <link>https://community.esri.com/t5/python-questions/sequential-field-calculation-with-python/m-p/229#M66</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Katherine, you can return these values as strings with numbers prefixed by zeros using the zfill method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.tutorialspoint.com/python/string_zfill.htm" title="http://www.tutorialspoint.com/python/string_zfill.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Python String zfill() Method&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;num = 1
str(num).zfill(4)

'0001'&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:01:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sequential-field-calculation-with-python/m-p/229#M66</guid>
      <dc:creator>ChristianWells</dc:creator>
      <dc:date>2021-12-10T20:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: Sequential field calculation with Python</title>
      <link>https://community.esri.com/t5/python-questions/sequential-field-calculation-with-python/m-p/230#M67</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Where do I add this into my code?&amp;nbsp; Or is this string code a separate process?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Jun 2016 15:00:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sequential-field-calculation-with-python/m-p/230#M67</guid>
      <dc:creator>KatyW</dc:creator>
      <dc:date>2016-06-01T15:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: Sequential field calculation with Python</title>
      <link>https://community.esri.com/t5/python-questions/sequential-field-calculation-with-python/m-p/231#M68</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is the solution!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use the original script to sequentially order.&amp;nbsp; After that is done field calculate again using the field you wish to add the extra digits to.&amp;nbsp; Then you can choose the string type as .zfill and add as many zeros as you would like.&amp;nbsp; I attached a screen shot to help clarify.&amp;nbsp; This gave me the result I was looking for!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Python.jpg" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/206506_Python.jpg" style="height: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Jun 2016 15:25:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sequential-field-calculation-with-python/m-p/231#M68</guid>
      <dc:creator>KatyW</dc:creator>
      <dc:date>2016-06-01T15:25:57Z</dc:date>
    </item>
    <item>
      <title>Re: Sequential field calculation with Python</title>
      <link>https://community.esri.com/t5/python-questions/sequential-field-calculation-with-python/m-p/232#M69</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Fantastic! Glad this worked out for you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Jun 2016 15:47:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sequential-field-calculation-with-python/m-p/232#M69</guid>
      <dc:creator>ChristianWells</dc:creator>
      <dc:date>2016-06-01T15:47:02Z</dc:date>
    </item>
  </channel>
</rss>

