<?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: looping after the last item in UpdadateCursor is very slow in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/looping-after-the-last-item-in-updadatecursor-is/m-p/1221085#M65833</link>
    <description>&lt;P&gt;Can you repost with it inserted in the Code window so we can see the indents?&lt;/P&gt;&lt;P&gt;I don't know if deleting the cursor on your last line will help?&lt;/P&gt;</description>
    <pubDate>Wed, 12 Oct 2022 13:58:45 GMT</pubDate>
    <dc:creator>Kara_Shindle</dc:creator>
    <dc:date>2022-10-12T13:58:45Z</dc:date>
    <item>
      <title>looping after the last item in UpdadateCursor is very slow</title>
      <link>https://community.esri.com/t5/python-questions/looping-after-the-last-item-in-updadatecursor-is/m-p/1221070#M65831</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;I'm trying to add&amp;nbsp; the polygons of lines that applied certain criteria to the last row and delete all the row beside the last one.&lt;/P&gt;&lt;P&gt;The problem is that it is very slow.&lt;/P&gt;&lt;P&gt;When I run debugger&amp;nbsp; it turns out that "for row in cursor:" is stuck for a long time after finishing the last item.&lt;/P&gt;&lt;P&gt;I mean, the line "cursor.updateRow(row)" is executed only in the last item. after that the debugger goes back&lt;BR /&gt;to the line&amp;nbsp;"for row in cursor:" and stays there for a few minutes.&lt;/P&gt;&lt;P&gt;Why is this happens?&lt;/P&gt;&lt;P&gt;with arcpy.da.UpdateCursor(my_layer, field_names, '"SETTLEMENT" = ' + str(x) ) as cursor:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; numberOfLinesLeft = sum(1 for row in cursor)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; cursor.reset()&lt;BR /&gt;&amp;nbsp; &amp;nbsp; flag=0&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for row in cursor:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if flag==0:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; temp_shape = row[0]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; flag=1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; temp_shape = temp_shape.union(row[0])&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if numberOfLinesLeft &amp;gt; 1:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cursor.deleteRow()&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; numberOfLinesLeft -=1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else: # We reached the last row, In this row we need to update it's shape&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; row[0]=temp_shape&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cursor.updateRow(row)&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2022 13:08:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/looping-after-the-last-item-in-updadatecursor-is/m-p/1221070#M65831</guid>
      <dc:creator>oferszekely</dc:creator>
      <dc:date>2022-10-12T13:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: looping after the last item in UpdadateCursor is very slow</title>
      <link>https://community.esri.com/t5/python-questions/looping-after-the-last-item-in-updadatecursor-is/m-p/1221085#M65833</link>
      <description>&lt;P&gt;Can you repost with it inserted in the Code window so we can see the indents?&lt;/P&gt;&lt;P&gt;I don't know if deleting the cursor on your last line will help?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2022 13:58:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/looping-after-the-last-item-in-updadatecursor-is/m-p/1221085#M65833</guid>
      <dc:creator>Kara_Shindle</dc:creator>
      <dc:date>2022-10-12T13:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: looping after the last item in UpdadateCursor is very slow</title>
      <link>https://community.esri.com/t5/python-questions/looping-after-the-last-item-in-updadatecursor-is/m-p/1221399#M65842</link>
      <description>&lt;P&gt;Yes.&lt;/P&gt;&lt;P&gt;I also want to mention that&amp;nbsp;I'm using Python 2.7.8&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    with arcpy.da.UpdateCursor(my_layer, field_names, '"SETTLEMENT" = ' + str(x) ) as cursor:
        counter = sum(1 for row in cursor)
        cursor.reset()
        flag=0
        for row in cursor:
            if flag==0:
                temp_shape = row[0]
                flag=1
            else:
                temp_shape = temp_shape.union(row[0])
            if counter &amp;gt; 1:
                cursor.deleteRow()
                counter -=1
            else: # We reached the last row, In this row we need to update it's shape
                row[0]=temp_shape
                cursor.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2022 06:34:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/looping-after-the-last-item-in-updadatecursor-is/m-p/1221399#M65842</guid>
      <dc:creator>oferszekely</dc:creator>
      <dc:date>2022-10-13T06:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: looping after the last item in UpdadateCursor is very slow</title>
      <link>https://community.esri.com/t5/python-questions/looping-after-the-last-item-in-updadatecursor-is/m-p/1221633#M65854</link>
      <description>&lt;P&gt;This looks like you are trying to do a dissolve operation?&lt;/P&gt;&lt;P&gt;Maybe revising the process to use the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/dissolve.htm" target="_blank" rel="noopener"&gt;dissolve.htm&lt;/A&gt; tool will work better?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2022 16:25:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/looping-after-the-last-item-in-updadatecursor-is/m-p/1221633#M65854</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-10-13T16:25:01Z</dc:date>
    </item>
  </channel>
</rss>

