Tuesday, June 19, 2012

SearchCursor (arcpy.da) 10.1 Continued

The new cursor objects contain a very helpful property called fields.  This property returns a tuple of field names defined in the field_names argument.  This means that if you pass "*" for all fields you can then get the associated field to the associated value.

Remember, cursor objects will ignore BLOB and Raster fields.

import arcpy
from arcpy import da
fc = r"c:\temp\demo_polygon.shp"
with da.SearchCursor(fc,"*") as rows:
   for field in rows.fields:
      print field

So in this example, the cursor will print all the fields being accessed.  It will also show the type of Shape field is being returned.  If all fields is used ("*"), then the SHAPE@XY property returned by default.