Skip to main content
Link to post this duplicates
Source Link
Jason Scheirer
  • 18k
  • 2
  • 54
  • 72

I can't see this documented in the Esri help files, so I'm entering it here for posterity.

According to Jason Scheirer from the Esri ArcPy team this is the intended behaviour (original Esri forums post):

The .next() method raises an error by design: it follows to the letter the Python Iterator Protocol, which requires the .next() method on an object to raise a StopIteration exception when it is exhausted.

The suggested approach is to use a for iterator on the cursor, ie without using the next() method at all:

with arcpy.da.SearchCursor(fc, fields) as cursor:
    for row in cursor:

In my case I wanted to perform an action when there was no row - I found that a Try, Except block worked well:

with arcpy.da.SearchCursor(fc, fields, where) as cursor:
    try:
        row = cursor.next()
        print(row)
    except StopIteration:
        print("No rows")
    except:
        print("something else went wrong")

I can't see this documented in the Esri help files, so I'm entering it here for posterity.

According to Jason Scheirer from the Esri ArcPy team this is the intended behaviour:

The .next() method raises an error by design: it follows to the letter the Python Iterator Protocol, which requires the .next() method on an object to raise a StopIteration exception when it is exhausted.

The suggested approach is to use a for iterator on the cursor, ie without using the next() method at all:

with arcpy.da.SearchCursor(fc, fields) as cursor:
    for row in cursor:

In my case I wanted to perform an action when there was no row - I found that a Try, Except block worked well:

with arcpy.da.SearchCursor(fc, fields, where) as cursor:
    try:
        row = cursor.next()
        print(row)
    except StopIteration:
        print("No rows")
    except:
        print("something else went wrong")

I can't see this documented in the Esri help files, so I'm entering it here for posterity.

According to Jason Scheirer from the Esri ArcPy team this is the intended behaviour (original Esri forums post):

The .next() method raises an error by design: it follows to the letter the Python Iterator Protocol, which requires the .next() method on an object to raise a StopIteration exception when it is exhausted.

The suggested approach is to use a for iterator on the cursor, ie without using the next() method at all:

with arcpy.da.SearchCursor(fc, fields) as cursor:
    for row in cursor:

In my case I wanted to perform an action when there was no row - I found that a Try, Except block worked well:

with arcpy.da.SearchCursor(fc, fields, where) as cursor:
    try:
        row = cursor.next()
        print(row)
    except StopIteration:
        print("No rows")
    except:
        print("something else went wrong")
removed ambiguity
Source Link
Stephen Lead
  • 21.2k
  • 18
  • 114
  • 241

I can't see this documented in the Esri help files, so I'm entering it here for posterity.

According to Jason Scheirer from the Esri ArcPy team this is the intended behaviour:

The .next() method raises an error by design: it follows to the letter the Python Iterator Protocol, which requires the .next() method on an object to raise a StopIteration exception when it is exhausted.

The suggested behaviourapproach is to use a for iterator on the cursor, ie without using the next() method at all:

with arcpy.da.SearchCursor(fc, fields) as cursor:
    for row in cursor:

In my case I wanted to perform an action when there was no row - I found that a Try, Except block worked well:

with arcpy.da.SearchCursor(fc, fields, where) as cursor:
    try:
        row = cursor.next()
        print(row)
    except StopIteration:
        print("No rows")
    except:
        print("something else went wrong")

I can't see this documented in the Esri help files, so I'm entering it here for posterity.

According to Jason Scheirer from the Esri ArcPy team this is the intended behaviour:

The .next() method raises an error by design: it follows to the letter the Python Iterator Protocol, which requires the .next() method on an object to raise a StopIteration exception when it is exhausted.

The suggested behaviour is to use a for iterator on the cursor, ie without using the next() method at all:

with arcpy.da.SearchCursor(fc, fields) as cursor:
    for row in cursor:

In my case I wanted to perform an action when there was no row - I found that a Try, Except block worked well:

with arcpy.da.SearchCursor(fc, fields, where) as cursor:
    try:
        row = cursor.next()
        print(row)
    except StopIteration:
        print("No rows")
    except:
        print("something else went wrong")

I can't see this documented in the Esri help files, so I'm entering it here for posterity.

According to Jason Scheirer from the Esri ArcPy team this is the intended behaviour:

The .next() method raises an error by design: it follows to the letter the Python Iterator Protocol, which requires the .next() method on an object to raise a StopIteration exception when it is exhausted.

The suggested approach is to use a for iterator on the cursor, ie without using the next() method at all:

with arcpy.da.SearchCursor(fc, fields) as cursor:
    for row in cursor:

In my case I wanted to perform an action when there was no row - I found that a Try, Except block worked well:

with arcpy.da.SearchCursor(fc, fields, where) as cursor:
    try:
        row = cursor.next()
        print(row)
    except StopIteration:
        print("No rows")
    except:
        print("something else went wrong")
removed the word "workaround"
Source Link
Stephen Lead
  • 21.2k
  • 18
  • 114
  • 241

I can't see this documented in the Esri help files, so I'm entering it here for posterity.

According to Jason Scheirer from the Esri ArcPy team this is the intended behaviour:

The .next() method raises an error by design: it follows to the letter the Python Iterator Protocol, which requires the .next() method on an object to raise a StopIteration exception when it is exhausted.

Workarounds include usingThe suggested behaviour is to use a for iterator on the cursor, ie notwithout using the next() method at all:

with arcpy.da.SearchCursor(fc, fields) as cursor:
    for row in cursor:

In my case I wanted to perform an action when there was no row - I found that a Try, Except block worked well:

with arcpy.da.SearchCursor(fc, fields, where) as cursor:
    try:
        row = cursor.next()
        print(row)
    except StopIteration:
        print("No rows")
    except:
        print("something else went wrong")

I can't see this documented in the Esri help files, so I'm entering it here for posterity.

According to Jason Scheirer from the Esri ArcPy team this is the intended behaviour:

The .next() method raises an error by design: it follows to the letter the Python Iterator Protocol, which requires the .next() method on an object to raise a StopIteration exception when it is exhausted.

Workarounds include using a for iterator on the cursor, ie not using the next() method at all:

with arcpy.da.SearchCursor(fc, fields) as cursor:
    for row in cursor:

In my case I wanted to perform an action when there was no row - I found that a Try, Except block worked well:

with arcpy.da.SearchCursor(fc, fields, where) as cursor:
    try:
        row = cursor.next()
        print(row)
    except StopIteration:
        print("No rows")
    except:
        print("something else went wrong")

I can't see this documented in the Esri help files, so I'm entering it here for posterity.

According to Jason Scheirer from the Esri ArcPy team this is the intended behaviour:

The .next() method raises an error by design: it follows to the letter the Python Iterator Protocol, which requires the .next() method on an object to raise a StopIteration exception when it is exhausted.

The suggested behaviour is to use a for iterator on the cursor, ie without using the next() method at all:

with arcpy.da.SearchCursor(fc, fields) as cursor:
    for row in cursor:

In my case I wanted to perform an action when there was no row - I found that a Try, Except block worked well:

with arcpy.da.SearchCursor(fc, fields, where) as cursor:
    try:
        row = cursor.next()
        print(row)
    except StopIteration:
        print("No rows")
    except:
        print("something else went wrong")
Fix formatting
Source Link
Jason Scheirer
  • 18k
  • 2
  • 54
  • 72
Loading
Source Link
Stephen Lead
  • 21.2k
  • 18
  • 114
  • 241
Loading