<?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: da.SearchCursor: Nested cursor will not 'reset' in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/da-searchcursor-nested-cursor-will-not-reset/m-p/1140282#M63653</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1371"&gt;@JoshuaBixby&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/295232"&gt;@CMV_Erik&lt;/a&gt; Sorry for the lag in response here, we've been swamped with project work so dev efforts get shelved.&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1371"&gt;@JoshuaBixby&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;&amp;nbsp;The reason the numbering isn't resetting is that the numbering is starting at 1 and going until the end for all records each time you call SpatialRenumberPoints.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;That is the exact insight I needed. To be real honest, I'm pretty sure my lack of this comprehension has confounded other things in the past too. I tried Erik's solution but it didn't work for, I presume, the exact reason you point out.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;My challenge is that I want to keep this function stand alone to be used in other scripts, so I'll try to make an &lt;STRIKE&gt;option argument like 'GroupField=None' or something.&lt;/STRIKE&gt; Nope that's a dead end...doh!&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;UPDATE:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Here are Josh's suggestions integrated and the code is now working!&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.SearchCursor('PlotCopy',['CLUSTER_ID'],sql_clause=(None, "GROUP BY CLUSTER_ID")) as cur:
    for row in cur:
        SpatialRenumberPoints('PlotCopy',1,'CLUSTER_ID',row[0])
        print("Updating {0}...".format(row[0]))&lt;/LI-CODE&gt;&lt;P&gt;which calls up the function:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def SpatialRenumberPoints(InLayer, StartNumber, GroupField=None, GroupID=None):
    arcpy.management.AddXY(InLayer)##Could verify if exists first##
    arcpy.AddField_management(InLayer, "NewID", 'LONG')##Could verify if exists first##
    fields = ['OID@','POINT_X','POINT_Y','NewID']
    if GroupField is None:
        WhereClause = None
    else:
        WhereClause =""" "{0}" = '{1}' """.format(GroupField, GroupID)
        print(WhereClause)
    sqlOrder = "ORDER BY {0} DESC, {1} ASC".format(fields[2], fields[1])   
    with arcpy.da.UpdateCursor(InLayer, fields, where_clause = WhereClause, sql_clause = (None, sqlOrder)) as cursor:
        for row in cursor:
            row[3]= StartNumber
            StartNumber = StartNumber + 1
            cursor.updateRow(row)
    del cursor, row  &lt;/LI-CODE&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1371"&gt;@JoshuaBixby&lt;/a&gt;&amp;nbsp; I'm guessing this looks pretty crude to you, any suggestions for improvements? Also, is the Group By in the Search Cursor even needed now? Thanks for any additional insight!&lt;/P&gt;</description>
    <pubDate>Thu, 03 Feb 2022 15:32:58 GMT</pubDate>
    <dc:creator>ZacharyHart</dc:creator>
    <dc:date>2022-02-03T15:32:58Z</dc:date>
    <item>
      <title>da.SearchCursor: Nested cursor will not 'reset'</title>
      <link>https://community.esri.com/t5/python-questions/da-searchcursor-nested-cursor-will-not-reset/m-p/1133570#M63504</link>
      <description>&lt;P&gt;To be fair, I don't know if this actually qualifies as a 'nested cursor' but it is a cursor calling up a function which has a cursor in it.&lt;/P&gt;&lt;P&gt;For starters, here is my function: it simply assigns a new identifier based on the points spatial location:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def SpatialRenumberPoints(InLayer, StartNumber):
    arcpy.management.AddXY(InLayer)##Could verify if exists first##
    arcpy.AddField_management(InLayer, "NewID", 'LONG')##Could verify if exists first##
    fields = ['OID@','POINT_X','POINT_Y','NewID']
    sqlOrder = "ORDER BY {0} DESC, {1} ASC".format(fields[2], fields[1])
    with arcpy.da.UpdateCursor(InLayer, fields,sql_clause = (None, sqlOrder)) as cursor:
        for row in cursor:
            row[3]= StartNumber
            StartNumber = StartNumber + 1
            cursor.updateRow(row)
    del cursor, row   &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When calling this function up in the Python Window, the next time it was run, the function would continue where it's last highest value left off. This was fixed by deleting out the cursor at the end of the function. Life is/was good.&lt;/P&gt;&lt;P&gt;Now, I realized I had a use case where I wanted to run the same tool against a dataset which has groups of points (identified by an attribute) and iterate through each group. No problem I thought, I'll just use use 'GROUP BY' for the SQL Clause in a search cursor. Like so:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.SearchCursor('PlotCopy',['CLUSTER_ID'],sql_clause=(None, "GROUP BY CLUSTER_ID")) as cur:
    for row in cur:
        SpatialRenumberPoints('PlotCopy',1)
        print(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only problem is that here again, the cursor isn't resetting or starting from '1' for each iteration.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ZacharyHart_0-1642103519681.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/31459iBF28F7B4782704DB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ZacharyHart_0-1642103519681.png" alt="ZacharyHart_0-1642103519681.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Perhaps I'm using GROUP BY inappropriately and should use my search cursor to setup a selection instead?&lt;/P&gt;&lt;P&gt;Thanks to anyone who can help!!&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2022 19:54:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/da-searchcursor-nested-cursor-will-not-reset/m-p/1133570#M63504</guid>
      <dc:creator>ZacharyHart</dc:creator>
      <dc:date>2022-01-13T19:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: da.SearchCursor: Nested cursor will not 'reset'</title>
      <link>https://community.esri.com/t5/python-questions/da-searchcursor-nested-cursor-will-not-reset/m-p/1133587#M63505</link>
      <description>&lt;P&gt;I like selections since you can use them then use the same code to set the selection to none, before carrying on with the next selection, I just don't skip the middle step of setting the selection to none after the initial selection and before the next (theoretically it shouldn't matter, but I like to make sure I am starting with a clean slate each time and not relying on underlying magic)&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2022 20:18:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/da-searchcursor-nested-cursor-will-not-reset/m-p/1133587#M63505</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-01-13T20:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: da.SearchCursor: Nested cursor will not 'reset'</title>
      <link>https://community.esri.com/t5/python-questions/da-searchcursor-nested-cursor-will-not-reset/m-p/1134106#M63521</link>
      <description>&lt;P&gt;In this case, you could get away without a parameter; just set StartNumber&amp;nbsp; = 1 as the first line of the function. If you want to retain the ability to change with a parameter, you could declare a new local variable inside the function and use it instead, like below. That way, every new function call should automatically start with 1 because the value is never shared outside the function.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;def &lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;SpatialRenumberPoints&lt;/SPAN&gt;(InLayer, paramStartNumber):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;    StartNumber = paramStartNumber&lt;/FONT&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;    arcpy.management.AddXY(InLayer)&lt;SPAN&gt;##Could verify if exists first##&lt;BR /&gt;&lt;/SPAN&gt;    arcpy.AddField_management(InLayer&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"NewID"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'LONG'&lt;/SPAN&gt;)&lt;SPAN&gt;##Could verify if exists first##&lt;BR /&gt;&lt;/SPAN&gt;    fields = [&lt;SPAN&gt;'OID@'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;'POINT_X'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;'POINT_Y'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;'NewID'&lt;/SPAN&gt;]&lt;BR /&gt;    sqlOrder = &lt;SPAN&gt;"ORDER BY {0} DESC, {1} ASC"&lt;/SPAN&gt;.format(fields[&lt;SPAN&gt;2&lt;/SPAN&gt;]&lt;SPAN&gt;, &lt;/SPAN&gt;fields[&lt;SPAN&gt;1&lt;/SPAN&gt;])&lt;BR /&gt;    &lt;SPAN&gt;with &lt;/SPAN&gt;arcpy.da.UpdateCursor(InLayer&lt;SPAN&gt;, &lt;/SPAN&gt;fields&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;sql_clause &lt;/SPAN&gt;= (&lt;SPAN&gt;None&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;sqlOrder)) &lt;SPAN&gt;as &lt;/SPAN&gt;cursor:&lt;BR /&gt;        &lt;SPAN&gt;for &lt;/SPAN&gt;row &lt;SPAN&gt;in &lt;/SPAN&gt;cursor:&lt;BR /&gt;            row[&lt;SPAN&gt;3&lt;/SPAN&gt;]= StartNumber&lt;BR /&gt;            StartNumber = StartNumber + &lt;SPAN&gt;1&lt;BR /&gt;&lt;/SPAN&gt;            cursor.updateRow(row)&lt;BR /&gt;    &lt;SPAN&gt;del &lt;/SPAN&gt;cursor&lt;SPAN&gt;, &lt;/SPAN&gt;row&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 22:38:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/da-searchcursor-nested-cursor-will-not-reset/m-p/1134106#M63521</guid>
      <dc:creator>CMV_Erik</dc:creator>
      <dc:date>2022-01-14T22:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: da.SearchCursor: Nested cursor will not 'reset'</title>
      <link>https://community.esri.com/t5/python-questions/da-searchcursor-nested-cursor-will-not-reset/m-p/1134373#M63522</link>
      <description>&lt;P&gt;In your second code snippet, the overall search cursor and the update cursor in SpatialRenumberPoints are independent of each other.&amp;nbsp; The reason the numbering isn't resetting is that the numbering is starting at 1 and going until the end for all records each time you call SpatialRenumberPoints.&lt;/P&gt;&lt;P&gt;What might work is if you pass the CLUSTER_ID value through to SpatialRenumberPoints as a new argument, and then add a SQL WHERE clause to the update cursor in SpatialRenumberPoints to filter records to only that CLUSTER_ID.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jan 2022 16:51:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/da-searchcursor-nested-cursor-will-not-reset/m-p/1134373#M63522</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2022-01-17T16:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: da.SearchCursor: Nested cursor will not 'reset'</title>
      <link>https://community.esri.com/t5/python-questions/da-searchcursor-nested-cursor-will-not-reset/m-p/1140278#M63652</link>
      <description>&lt;P&gt;I clicked too soon. Declaring the variable within the function did not fix the issue. I think I need to consider something like what &lt;A href="https://community.esri.com/t5/user/viewprofilepage/user-id/1371" target="_blank"&gt;@JoshuaBixby&lt;/A&gt;&amp;nbsp; suggested.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 14:30:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/da-searchcursor-nested-cursor-will-not-reset/m-p/1140278#M63652</guid>
      <dc:creator>ZacharyHart</dc:creator>
      <dc:date>2022-02-03T14:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: da.SearchCursor: Nested cursor will not 'reset'</title>
      <link>https://community.esri.com/t5/python-questions/da-searchcursor-nested-cursor-will-not-reset/m-p/1140282#M63653</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1371"&gt;@JoshuaBixby&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/295232"&gt;@CMV_Erik&lt;/a&gt; Sorry for the lag in response here, we've been swamped with project work so dev efforts get shelved.&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1371"&gt;@JoshuaBixby&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;&amp;nbsp;The reason the numbering isn't resetting is that the numbering is starting at 1 and going until the end for all records each time you call SpatialRenumberPoints.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;That is the exact insight I needed. To be real honest, I'm pretty sure my lack of this comprehension has confounded other things in the past too. I tried Erik's solution but it didn't work for, I presume, the exact reason you point out.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;My challenge is that I want to keep this function stand alone to be used in other scripts, so I'll try to make an &lt;STRIKE&gt;option argument like 'GroupField=None' or something.&lt;/STRIKE&gt; Nope that's a dead end...doh!&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;UPDATE:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Here are Josh's suggestions integrated and the code is now working!&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.SearchCursor('PlotCopy',['CLUSTER_ID'],sql_clause=(None, "GROUP BY CLUSTER_ID")) as cur:
    for row in cur:
        SpatialRenumberPoints('PlotCopy',1,'CLUSTER_ID',row[0])
        print("Updating {0}...".format(row[0]))&lt;/LI-CODE&gt;&lt;P&gt;which calls up the function:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def SpatialRenumberPoints(InLayer, StartNumber, GroupField=None, GroupID=None):
    arcpy.management.AddXY(InLayer)##Could verify if exists first##
    arcpy.AddField_management(InLayer, "NewID", 'LONG')##Could verify if exists first##
    fields = ['OID@','POINT_X','POINT_Y','NewID']
    if GroupField is None:
        WhereClause = None
    else:
        WhereClause =""" "{0}" = '{1}' """.format(GroupField, GroupID)
        print(WhereClause)
    sqlOrder = "ORDER BY {0} DESC, {1} ASC".format(fields[2], fields[1])   
    with arcpy.da.UpdateCursor(InLayer, fields, where_clause = WhereClause, sql_clause = (None, sqlOrder)) as cursor:
        for row in cursor:
            row[3]= StartNumber
            StartNumber = StartNumber + 1
            cursor.updateRow(row)
    del cursor, row  &lt;/LI-CODE&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1371"&gt;@JoshuaBixby&lt;/a&gt;&amp;nbsp; I'm guessing this looks pretty crude to you, any suggestions for improvements? Also, is the Group By in the Search Cursor even needed now? Thanks for any additional insight!&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 15:32:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/da-searchcursor-nested-cursor-will-not-reset/m-p/1140282#M63653</guid>
      <dc:creator>ZacharyHart</dc:creator>
      <dc:date>2022-02-03T15:32:58Z</dc:date>
    </item>
    <item>
      <title>Re: da.SearchCursor: Nested cursor will not 'reset'</title>
      <link>https://community.esri.com/t5/python-questions/da-searchcursor-nested-cursor-will-not-reset/m-p/1140335#M63657</link>
      <description>&lt;P&gt;I didn't look closely enough at the code the first time, but I agree. &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1371"&gt;@JoshuaBixby&lt;/a&gt; nailed it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 15:41:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/da-searchcursor-nested-cursor-will-not-reset/m-p/1140335#M63657</guid>
      <dc:creator>CMV_Erik</dc:creator>
      <dc:date>2022-02-03T15:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: da.SearchCursor: Nested cursor will not 'reset'</title>
      <link>https://community.esri.com/t5/python-questions/da-searchcursor-nested-cursor-will-not-reset/m-p/1140509#M63658</link>
      <description>&lt;P&gt;To try to make up for my oversight, an alternate approach:&amp;nbsp;&lt;/P&gt;&lt;P&gt;If there's only one dataset involved, this could be also done with a single cursor &amp;amp; no functions if you sort the update cursor by CLUSTERID. More work per record, but fewer geodatabase requests.&amp;nbsp;Something like:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;InLayer = &lt;SPAN&gt;'PlotCopy'&lt;BR /&gt;&lt;/SPAN&gt;arcpy.management.AddXY(InLayer)&lt;SPAN&gt;##Could verify if exists first##&lt;BR /&gt;&lt;/SPAN&gt;arcpy.AddField_management(InLayer&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"NewID"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'LONG'&lt;/SPAN&gt;)&lt;SPAN&gt;##Could verify if exists first##&lt;BR /&gt;&lt;/SPAN&gt;fields = [&lt;SPAN&gt;'OID@'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;'POINT_X'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;'POINT_Y'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;'NewID'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'CLUSTERID'&lt;/SPAN&gt;]&lt;BR /&gt;sqlOrder = &lt;SPAN&gt;"ORDER BY &lt;FONT color="#FF00FF"&gt;{0} ASC,&lt;/FONT&gt; {1} DESC, {2] ASC"&lt;/SPAN&gt;.format(&lt;FONT color="#FF00FF"&gt;fields[&lt;SPAN&gt;4&lt;/SPAN&gt;]&lt;/FONT&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;fields[&lt;SPAN&gt;2&lt;/SPAN&gt;]&lt;SPAN&gt;, &lt;/SPAN&gt;fields[&lt;SPAN&gt;1&lt;/SPAN&gt;])&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;last_cluster_id = &lt;/FONT&gt;&lt;SPAN&gt;&lt;FONT color="#FF00FF"&gt;0&lt;/FONT&gt;&lt;BR /&gt;&lt;/SPAN&gt;StartNumber = &lt;SPAN&gt;1&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;with &lt;/SPAN&gt;arcpy.da.UpdateCursor(InLayer&lt;SPAN&gt;, &lt;/SPAN&gt;fields&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;sql_clause &lt;/SPAN&gt;= (&lt;SPAN&gt;None, &lt;/SPAN&gt;sqlOrder)) &lt;SPAN&gt;as &lt;/SPAN&gt;cursor_sorted_by_cluster_id:&lt;BR /&gt;    &lt;SPAN&gt;for &lt;/SPAN&gt;row &lt;SPAN&gt;in &lt;/SPAN&gt;cursor_sorted_by_cluster_id:&lt;BR /&gt;        # test if the clusterid was the same as the last one&lt;BR /&gt;        &lt;FONT color="#FF00FF"&gt;&lt;SPAN&gt;if &lt;/SPAN&gt;row[&lt;SPAN&gt;4&lt;/SPAN&gt;] == last_cluster_id:&lt;/FONT&gt;   # still the same CLUSTERID group&lt;BR /&gt;            StartNumber += &lt;SPAN&gt;1            # increment the counter&lt;BR /&gt;&lt;/SPAN&gt;        &lt;FONT color="#FF00FF"&gt;&lt;SPAN&gt;else&lt;/SPAN&gt;:    &lt;/FONT&gt;                       # starting a new CLUSTERID group - reset&lt;BR /&gt;        &lt;FONT color="#FF00FF"&gt;    last_cluster_id = row[&lt;SPAN&gt;4&lt;/SPAN&gt;] &lt;/FONT&gt;   # change the value   &lt;BR /&gt;        &lt;FONT color="#FF00FF"&gt;    StartNumber = &lt;/FONT&gt;&lt;SPAN&gt;&lt;FONT color="#FF00FF"&gt;1&lt;/FONT&gt;             # reset&amp;nbsp;the counter&lt;BR /&gt;&lt;/SPAN&gt;        row[&lt;SPAN&gt;3&lt;/SPAN&gt;] = StartNumber&lt;BR /&gt;        cursor_sorted_by_cluster_id.updateRow(row)&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 19:41:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/da-searchcursor-nested-cursor-will-not-reset/m-p/1140509#M63658</guid>
      <dc:creator>CMV_Erik</dc:creator>
      <dc:date>2022-02-03T19:41:20Z</dc:date>
    </item>
  </channel>
</rss>

