<?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: Python Sequential Numbering in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108668#M46873</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/343212"&gt;@DavidForbuss1&lt;/a&gt;, don't worry, &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3374"&gt;@JoeBorgione&lt;/a&gt;&amp;nbsp; is going to be like Dan P. and be more active on Esri Community after he retires from his day job. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Oct 2021 00:39:10 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2021-10-19T00:39:10Z</dc:date>
    <item>
      <title>Python Sequential Numbering</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108116#M46773</link>
      <description>&lt;P&gt;Hi everyone!&lt;/P&gt;&lt;P&gt;I'm using the sequential numbering script in the field calculator, and I'm trying to modify it to iterate through field values from another field so that the sequence starts over for each of the unique other values.&amp;nbsp; My table looks like this --&amp;gt;&amp;gt;&amp;nbsp; I'm trying to generate a Name with a Basin ID as the prefix.&amp;nbsp; For now, I've been just manually selecting the basins and running the script for each one, but I'd like to be able to have the script run through them all at once:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DavidForbuss1_3-1634332431187.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25336i000CACEE046F149A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DavidForbuss1_3-1634332431187.png" alt="DavidForbuss1_3-1634332431187.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Script I'm using:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DavidForbuss1_1-1634332233141.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25334i109E389009F10707/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DavidForbuss1_1-1634332233141.png" alt="DavidForbuss1_1-1634332233141.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SequentialNumber()&lt;/P&gt;&lt;P&gt;# Calculates a sequential number&lt;BR /&gt;# More calculator examples at esriurl.com/CalculatorExamples&lt;BR /&gt;rec=0&lt;BR /&gt;def SequentialNumber():&lt;BR /&gt;global rec&lt;BR /&gt;pStart = 1&lt;BR /&gt;pInterval = 1&lt;BR /&gt;if (rec == 0):&lt;BR /&gt;rec = pStart&lt;BR /&gt;else:&lt;BR /&gt;rec = rec + pInterval&lt;BR /&gt;return "WA1MH"+str(rec).zfill(4)&lt;/P&gt;&lt;P&gt;I'm pretty rusty on python...any help would be appreciated!&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;David Forbuss&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;GIS Technician&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Rogue Valley Sewer Services&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;P O Box 3130&lt;/P&gt;&lt;P&gt;Central Point OR 97502&lt;/P&gt;&lt;P&gt;541-664-6300&lt;/P&gt;&lt;P&gt;&lt;A href="mailto:dforbuss@rvss.us" target="_blank" rel="noopener"&gt;dforbuss@rvss.us&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Oct 2021 21:16:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108116#M46773</guid>
      <dc:creator>DavidForbuss1</dc:creator>
      <dc:date>2021-10-15T21:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: Python Sequential Numbering</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108135#M46776</link>
      <description>&lt;P&gt;To go through the individual records you are going to need an &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/updatecursor-class.htm" target="_self"&gt;update cursor.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I'm not sure why you are using a global variable designator.&amp;nbsp; There really is no need to and there a lot of pythonistas that frown upon their use.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Oct 2021 22:13:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108135#M46776</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-10-15T22:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: Python Sequential Numbering</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108138#M46777</link>
      <description>&lt;P&gt;I just used the default script that populates when you click the helper...the global is built into it.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DavidForbuss1_0-1634336074922.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25341i46290F05B8D11EEA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DavidForbuss1_0-1634336074922.png" alt="DavidForbuss1_0-1634336074922.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Oct 2021 22:14:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108138#M46777</guid>
      <dc:creator>DavidForbuss1</dc:creator>
      <dc:date>2021-10-15T22:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: Python Sequential Numbering</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108146#M46778</link>
      <description>&lt;P&gt;You can use that for a start and build it into a cursor.&amp;nbsp; Otherwise you'll be stuck running it iteratively by hand.&lt;/P&gt;&lt;P&gt;Assuming you have several different prefixes, you'll probably need to work through a list of them, and plug that value as your prefix and then concatenate the number you want. It's late friday afternoon and I've got my eye on a cold adult beverage.&amp;nbsp; Do some hacking and if you need a hand, post it up on monday.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Oct 2021 22:29:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108146#M46778</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-10-15T22:29:25Z</dc:date>
    </item>
    <item>
      <title>Re: Python Sequential Numbering</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108409#M46830</link>
      <description>&lt;P&gt;I was thinking more along the lines of defining a variable like:&lt;/P&gt;&lt;P&gt;basins=!Basin_ID!&lt;/P&gt;&lt;P&gt;Then just building that into the return portion:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;return str(basins)+"MH"+str(rec).zfill(4)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I keep getting syntax errors though.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 14:21:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108409#M46830</guid>
      <dc:creator>DavidForbuss1</dc:creator>
      <dc:date>2021-10-18T14:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: Python Sequential Numbering</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108444#M46835</link>
      <description>&lt;P&gt;I'm not a fan of using the plus sign for concatenating strings, and really prefer the &lt;A href="https://realpython.com/python-f-strings/" target="_self"&gt;f string method&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Here is an example:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;rec = 0

for i in range(1,10):
    print(f'MH{str(i).zfill(4)}')
    &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Without seeing your entire code block, it's hard saying what the syntax error might be.&amp;nbsp; Can you include a sample of your data in csv form?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 15:28:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108444#M46835</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-10-18T15:28:41Z</dc:date>
    </item>
    <item>
      <title>Re: Python Sequential Numbering</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108451#M46843</link>
      <description>&lt;P&gt;It is always helpful to paste the exact error and traceback rather than just saying "getting syntax errors."&amp;nbsp; Does your syntax error look like this?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;&amp;gt;&amp;gt;&amp;gt; basins=!Basin_ID!
  File "&amp;lt;stdin&amp;gt;", line 1
    basins=!Basin_ID!
           ^
SyntaxError: invalid syntax
&amp;gt;&amp;gt;&amp;gt; &lt;/LI-CODE&gt;&lt;P&gt;You can't assign a column value using the Esri's exclamation point syntax within the code block, it has to be in the field expression and passed to a parameter defined for the function.&lt;/P&gt;&lt;P&gt;I suggest you read through &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field-examples.htm" target="_blank"&gt;Calculate Field Python examples—ArcGIS Pro | Documentation&lt;/A&gt;, it has many examples, and should give you a better idea of how to pass table values to Python functions.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 15:37:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108451#M46843</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-10-18T15:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: Python Sequential Numbering</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108454#M46844</link>
      <description>&lt;P&gt;Here's my data in csv format.&amp;nbsp; I've started filling in some of the descriptions by manually selecting the basins and running the sequential script, but it's likely that the basin names will change in the future, so that's my motivation to get a script that can be run again to repop to the description column.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 15:48:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108454#M46844</guid>
      <dc:creator>DavidForbuss1</dc:creator>
      <dc:date>2021-10-18T15:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: Python Sequential Numbering</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108497#M46855</link>
      <description>&lt;P&gt;Here is how I ended up doing it with an update cursor:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

table = r'C:\GIS\Forbuss\Forbuss.gdb\ForbussDataTable'
nameTable = r'C:\GIS\Forbuss\Forbuss.gdb\ForbussDataTable_Statistics'
nameList = [r[0] for r in  arcpy.da.SearchCursor(nameTable,'basin_name','basin_name IS NOT NULL') ]

arcpy.management.MakeTableView(table,'tableView')

for name in nameList:
    select = f"basin_name = '{name}'"
    fields = ['description','basin_name']
    with arcpy.da.UpdateCursor('tableView',fields,select) as cursor:
        rec = 0
        for row in cursor:
            rec+=1
            row[0] = (f'{row[1]}{str(rec).zfill(4)}')
            cursor.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;Lines 3,4 &amp;amp; 5 set the stage; I converted your csv into a fgdb table, and then using list comprehension and a search cursor, created a list of basin names (where the basin name is not null).&amp;nbsp; Then in Line 7 I turn the original table into a table view since I'm running this as a stand alone script.&amp;nbsp; Finally at row 9 I iterate through the list of basin names and with an update cursor update the 'description' field.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 17:24:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108497#M46855</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-10-18T17:24:46Z</dc:date>
    </item>
    <item>
      <title>Re: Python Sequential Numbering</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108526#M46858</link>
      <description>&lt;P&gt;Joe -- You're not allowed to retire...that worked!!&amp;nbsp; Thank you so much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 18:27:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108526#M46858</guid>
      <dc:creator>DavidForbuss1</dc:creator>
      <dc:date>2021-10-18T18:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: Python Sequential Numbering</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108538#M46860</link>
      <description>&lt;P&gt;I'm glad it worked for you.&amp;nbsp; For me, I much prefer to use an update cursor than the field calculator in this kind of situation.&lt;/P&gt;&lt;P&gt;With respect to retirement, it's in the very near future for me, so ask away!&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 18:56:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108538#M46860</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-10-18T18:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: Python Sequential Numbering</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108668#M46873</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/343212"&gt;@DavidForbuss1&lt;/a&gt;, don't worry, &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3374"&gt;@JoeBorgione&lt;/a&gt;&amp;nbsp; is going to be like Dan P. and be more active on Esri Community after he retires from his day job. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Oct 2021 00:39:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-sequential-numbering/m-p/1108668#M46873</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-10-19T00:39:10Z</dc:date>
    </item>
  </channel>
</rss>

