Select to view content in your preferred language

Version 10.0 search cursor not resetting?

482
1
Jump to solution
07-16-2012 12:17 PM
HarryBowman
Deactivated User
Running in 10.0. Was trying to reset a search cursor in some code, and it didn't work. Tried this little snippet, and it didn't work either.

cur = arcpy.SearchCursor("c1") row = cur.next() while row:  print row.getValue("FID")  row = cur.next() cur.reset() row = cur.next() print row.getValue("FID")


The last print statement returns an error, saying the row is NoneType object. I was expecting the cursor to reset and respond to next. What did I do wrong?
0 Kudos
1 Solution

Accepted Solutions
markdenil
Frequent Contributor
All you did wrong was expect reset() to work.
In fact it does not work, at least not on a feature table.
This fact is mentioned somewhere in the help files,
but only in passing, and not at all on most of the cursor pages.
(and I couldn't find it myself, when I looked just now)

On the Cursor page, for example, under Methods, reset() is only a heading;
it has no little explanation table.

In order to start at the top again, you have to start a new cursor.

View solution in original post

0 Kudos
1 Reply
markdenil
Frequent Contributor
All you did wrong was expect reset() to work.
In fact it does not work, at least not on a feature table.
This fact is mentioned somewhere in the help files,
but only in passing, and not at all on most of the cursor pages.
(and I couldn't find it myself, when I looked just now)

On the Cursor page, for example, under Methods, reset() is only a heading;
it has no little explanation table.

In order to start at the top again, you have to start a new cursor.
0 Kudos