<?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: Why does the next() method fail after the last record, using arcpy.da.SearchCurso in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208854#M16164</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Since a cursor outputs to either a list or a dictionary I believe you can use the len() operator on the cursor output.&amp;nbsp; So I think this would work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fc = "C:\Program Files (x86)\ArcGIS\Desktop10.2\ArcGlobeData\continent.shp"
fields = ["CONTINENT"]
where = "CONTINENT = 'Asia'"
with arcpy.da.SearchCursor(fc, fields, where) as cursor:
j = len(cursor)
if j &amp;gt; 5:
&amp;nbsp; j = 5
for i in range(0, j):&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 10:18:58 GMT</pubDate>
    <dc:creator>RichardFairhurst</dc:creator>
    <dc:date>2021-12-11T10:18:58Z</dc:date>
    <item>
      <title>Why does the next() method fail after the last record, using arcpy.da.SearchCursor?</title>
      <link>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208848#M16158</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Using the older &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://resources.arcgis.com/en/help/main/10.2/index.html#//03q300000070000000" rel="nofollow" target="_blank"&gt;arcpy.SearchCursor&lt;/A&gt;&lt;SPAN&gt;, the next() method would return &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;Nothing&lt;/SPAN&gt;&lt;SPAN&gt; once the last record had been passed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Using the newer &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://resources.arcgis.com/en/help/main/10.2/index.html#/SearchCursor/018w00000011000000/" rel="nofollow" target="_blank"&gt;arcpy.da.SearchCursor&lt;/A&gt;&lt;SPAN&gt;, I'm finding that the next() method crashes the script if there are no more records. To illustrate:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy&amp;nbsp;&amp;nbsp; fc = "C:\Program Files (x86)\ArcGIS\Desktop10.2\ArcGlobeData\continent.shp" fields = ["CONTINENT"] where = "CONTINENT = 'Asia'" cursor = arcpy.da.SearchCursor(fc, fields, where) for i in range(0,5): &amp;nbsp;&amp;nbsp;&amp;nbsp; row = cursor.next() &amp;nbsp;&amp;nbsp;&amp;nbsp; print(row)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There is only one record in the cursor, so the first time it iterates the name is printed. But the second iteration throws a &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;StopIteration&lt;/SPAN&gt;&lt;SPAN&gt; error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I believe this is a bug - the cursor should return Nothing, allowing us to handle the situation. &lt;/SPAN&gt;&lt;STRONG&gt;At the very least, this behaviour should be documented.&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(I know there is an alternative method using &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;&lt;SPAN style="color:#0000FF;"&gt;for &lt;/SPAN&gt;&lt;SPAN style="color:#4D4D4D;"&gt;row &lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;"&gt;in &lt;/SPAN&gt;&lt;SPAN style="color:#4D4D4D;"&gt;cursor&lt;/SPAN&gt;&lt;SPAN style="color:#4D4D4D;"&gt;:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt; but my point is that the next() method should not throw an error after the last record. Also, in my case I'm looking for situations where there are no records so I can perform an action - this doesn't work when using &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;&lt;SPAN style="color:#0000FF;"&gt;for &lt;/SPAN&gt;&lt;SPAN style="color:#4D4D4D;"&gt;row &lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;"&gt;in &lt;/SPAN&gt;&lt;SPAN style="color:#4D4D4D;"&gt;cursor&lt;/SPAN&gt;&lt;SPAN style="color:#4D4D4D;"&gt;:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Steve&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 22:40:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208848#M16158</guid>
      <dc:creator>StephenLead</dc:creator>
      <dc:date>2014-04-30T22:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the next() method fail after the last record, using arcpy.da.SearchCurso</title>
      <link>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208849#M16159</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Using the older &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//03q300000070000000" rel="nofollow noopener noreferrer" target="_blank"&gt;arcpy.SearchCursor&lt;/A&gt;, the next() method would return &lt;SPAN style="font-style:italic;"&gt;Nothing&lt;/SPAN&gt; once the last record had been passed.&lt;BR /&gt;&lt;BR /&gt;Using the newer &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/SearchCursor/018w00000011000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;arcpy.da.SearchCursor&lt;/A&gt;, I'm finding that the next() method crashes the script if there are no more records. &lt;BR /&gt;&lt;BR /&gt;(I know there is an alternative method using &lt;SPAN style="font-style:italic;"&gt;&lt;SPAN style="color:#0000FF;"&gt;for &lt;/SPAN&gt;&lt;SPAN style="color:#4D4D4D;"&gt;row &lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;"&gt;in &lt;/SPAN&gt;&lt;SPAN style="color:#4D4D4D;"&gt;cursor&lt;/SPAN&gt;&lt;SPAN style="color:#4D4D4D;"&gt;:&lt;/SPAN&gt;&lt;/SPAN&gt; but my point is that the next() method should not throw an error after the last record. Also, in my case I'm looking for situations where there are no records so I can perform an action - this doesn't work when using &lt;SPAN style="font-style:italic;"&gt;&lt;SPAN style="color:#0000FF;"&gt;for &lt;/SPAN&gt;&lt;SPAN style="color:#4D4D4D;"&gt;row &lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;"&gt;in &lt;/SPAN&gt;&lt;SPAN style="color:#4D4D4D;"&gt;cursor&lt;/SPAN&gt;&lt;SPAN style="color:#4D4D4D;"&gt;:&lt;/SPAN&gt;&lt;/SPAN&gt;).&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I agree with you, Steve - may want to bring that up with support... I'm afraid they will however tell you that the new behavior is more pythonic, since the StopIteration error can easily handled as an expect exception and is more detailed information than just getting None. Since they did change the behavior, it should be documented under the .next() method I think! &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That said, I recommending avoiding the old (9.2-style, really) enumeration approach using next() with arcpy.da.cursor. Also, the new suggested use of the "with" construct is much better as it closes the cursor for you when you exit the with block, no matter what happens.&amp;nbsp; As for handling the no rows situation, I've done that in the code below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fc = "C:\Program Files (x86)\ArcGIS\Desktop10.2\ArcGlobeData\continent.shp"
fields = ["CONTINENT"]
where = "CONTINENT = 'Asia'"
k = 0
with arcpy.da.SearchCursor(fc, fields, where) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; k += 1
if k == 0: 
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "No records!"
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:18:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208849#M16159</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T10:18:50Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the next() method fail after the last record, using arcpy.da.SearchCurso</title>
      <link>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208850#M16160</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Curtis. I'm doing something similar to handle it (maybe this is the correct method - but as you say it'd be nice if it was documented).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
with arcpy.da.SearchCursor(outFC, fields, whereClause) as sCursor:
&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; #See if there are any records returned. If this throws an error, this means
&amp;nbsp;&amp;nbsp;&amp;nbsp; #there are no records, in which case we need to add one
&amp;nbsp;&amp;nbsp;&amp;nbsp; sRow = sCursor.next()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Create a new point in the output geodatabase
&amp;nbsp;&amp;nbsp;&amp;nbsp; pt = (lon, lat)
&amp;nbsp;&amp;nbsp;&amp;nbsp; iCursor.insertRow([pt, ID])
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I should probably check that the error was of type StopIteration for completeness.....&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:18:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208850#M16160</guid>
      <dc:creator>StephenLead</dc:creator>
      <dc:date>2021-12-11T10:18:53Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the next() method fail after the last record, using arcpy.da.SearchCurso</title>
      <link>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208851#M16161</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;When I want to verify a selection was made I use code like this ("parcels" is a layer that may or may not contain a selection):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;if int(arcpy.GetCount_management(parcels).getOutput(0)) &amp;gt; 0:&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 23:07:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208851#M16161</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-04-30T23:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the next() method fail after the last record, using arcpy.da.SearchCurso</title>
      <link>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208852#M16162</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;When I want to verify a selection was made I use code like this ("parcels" is a layer that may or may not contain a selection):&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;if int(arcpy.GetCount_management(parcels).getOutput(0)) &amp;gt; 0:&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I guess I'd need to couple this with a Select By Attributes first, in order to ensure my whereClause was being used. But it's a good workaround - thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 23:11:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208852#M16162</guid>
      <dc:creator>StephenLead</dc:creator>
      <dc:date>2014-04-30T23:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the next() method fail after the last record, using arcpy.da.SearchCurso</title>
      <link>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208853#M16163</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If the actual amount counted made a difference I store the result of the count to a variable and then use it in further tests.&amp;nbsp; This is particularly useful where a single row selection needs much less processing than a multi-record selection or where excessively large selections are not expected.&amp;nbsp; For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;parcelsCount = int(arcpy.GetCount_management(parcels).getOutput(0))
if 0 &amp;lt; parcelsCount &amp;lt; 2:
&amp;nbsp; # do something
elif 1 &amp;lt; parcelsCount &amp;lt; 1000:
&amp;nbsp; # do something else
else:
&amp;nbsp; # do a different thing&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:18:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208853#M16163</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-11T10:18:56Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the next() method fail after the last record, using arcpy.da.SearchCurso</title>
      <link>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208854#M16164</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Since a cursor outputs to either a list or a dictionary I believe you can use the len() operator on the cursor output.&amp;nbsp; So I think this would work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fc = "C:\Program Files (x86)\ArcGIS\Desktop10.2\ArcGlobeData\continent.shp"
fields = ["CONTINENT"]
where = "CONTINENT = 'Asia'"
with arcpy.da.SearchCursor(fc, fields, where) as cursor:
j = len(cursor)
if j &amp;gt; 5:
&amp;nbsp; j = 5
for i in range(0, j):&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:18:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208854#M16164</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-11T10:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the next() method fail after the last record, using arcpy.da.SearchCurso</title>
      <link>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208855#M16165</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Since a cursor outputs to either a list or a dictionary I believe you can use the len() operator on the cursor output&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Unfortunately I don't think that's correct.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]33500[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've updated my original question to say that the fact that cursor.next() crashes after the last record should be reflected in the documentation - it's clear there are lots of workarounds to this "feature".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the assistance,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Steve&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 23:37:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208855#M16165</guid>
      <dc:creator>StephenLead</dc:creator>
      <dc:date>2014-04-30T23:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the next() method fail after the last record, using arcpy.da.SearchCurso</title>
      <link>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208856#M16166</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Unfortunately I don't think that's correct.&lt;BR /&gt;&lt;BR /&gt;[ATTACH=CONFIG]33500[/ATTACH]&lt;BR /&gt;&lt;BR /&gt;I've updated my original question to say that the fact that cursor.next() crashes after the last record should be reflected in the documentation - it's clear there are lots of workarounds to this "feature".&lt;BR /&gt;&lt;BR /&gt;Thanks for the assistance,&lt;BR /&gt;Steve&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It was worth a shot.&amp;nbsp; I wonder if the old cursor could do this (although I would still recommend using the da cursor)?&amp;nbsp; And if no geometry was involved the cursor could be read into a dictionary with a standard for loop and then processed much faster and fluidly than using just a cursor.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 23:43:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208856#M16166</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-04-30T23:43:53Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the next() method fail after the last record, using arcpy.da.SearchCurso</title>
      <link>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208857#M16167</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt; .next()&lt;/SPAN&gt;&lt;SPAN&gt; method raises an error by design: it follows to the letter &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://legacy.python.org/dev/peps/pep-0234/" rel="nofollow" target="_blank"&gt;the Python Iterator Protocol&lt;/A&gt;&lt;SPAN&gt;, which requires the &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;.next()&lt;/SPAN&gt;&lt;SPAN&gt; method on an object to raise a &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;StopIteration&lt;/SPAN&gt;&lt;SPAN&gt; exception when it is exhausted.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I very strongly recommend you refactor your script to read as such instead (using &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://docs.python.org/2/library/itertools.html" rel="nofollow" target="_blank"&gt;itertools&lt;/A&gt;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import itertools import arcpy&amp;nbsp; fc = "C:\Program Files (x86)\ArcGIS\Desktop10.2\ArcGlobeData\continent.shp" fields = ["CONTINENT"] where = "CONTINENT = 'Asia'" with arcpy.da.SearchCursor(fc, fields, where) as cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp; for row in itertools.islice(cursor, 5): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 23:44:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208857#M16167</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2014-04-30T23:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the next() method fail after the last record, using arcpy.da.SearchCurso</title>
      <link>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208858#M16168</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Jason. Could you add this information to the help file entries for &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/SearchCursor/018w00000011000000/"&gt;SearchCursor&lt;/A&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/InsertCursor/018w0000000t000000/"&gt;InsertCursor &lt;/A&gt;&lt;SPAN&gt;and &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/UpdateCursor/018w00000014000000/"&gt;UpdateCursor&lt;/A&gt;&lt;SPAN&gt;?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Apr 2014 23:49:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-does-the-next-method-fail-after-the-last/m-p/208858#M16168</guid>
      <dc:creator>StephenLead</dc:creator>
      <dc:date>2014-04-30T23:49:05Z</dc:date>
    </item>
  </channel>
</rss>

