Now that you know how to traverse the table horizontally, reading the fields that are available, let's examine how to read up and down through the table records.
The search cursor
The arcpy module contains some objects called cursors that allow you to move through records in a table. Cursors are not unique to ArcGIS scripting; in fact, if you've worked in ArcObjects before, this concept of a cursor is probably familiar to you. The first cursor we'll look at is the search cursor, since it's designed for simple reading of data. The common workflow is:
1- Create the search cursor. This is done through the method arcpy.SearchCursor(). This method takes several parameters in which you specify which dataset and, optionally, which specific rows you want to read.
2 - Call SearchCursor.next() to read the first row.
3 - Start a loop that will exit when there are no more rows available to read.
4 - Do something with the values in the current row.
5 - Call SearchCursor.next() to move on to the next row. Because you created a loop, this puts you back at the previous step if there is another row available to be read. If there are no more rows, the loop condition is not met and the loop terminates.
When you first try to understand cursors, it may help to visualize the attribute table with an arrow pointing at the "current row." When the cursor is first created, that arrow is pointing just above the first row in the table. The first time the next() method is called, the arrow moves down to the first row (and returns a reference to that row). Each time next() is called, the arrow moves down one row. If next() is called when the arrow is pointing at the last row, a special data type called None is returned.....