Select to view content in your preferred language

iterator col in row object

1128
3
08-03-2011 11:12 AM
HemingZhu
Frequent Contributor
I was stucked on get the field names from a row object. I have a feature set created from the query task. I want to pass this feature set to a geoprocessing so i can use a search cursor to iterator each feature. However, unless you specify the field name explicitly, you can not iterator the cols in the row. And there is no Describe or list object for featureset so you can get field info. I do want to pass additional parameter to just list the field names for the feature set. Does anyone have any idea how to get field names of a featureset through arcpy or Python?
Tags (2)
0 Kudos
3 Replies
MichaelFaulcon1
Deactivated User
Any updates on this?
0 Kudos
curtvprice
MVP Alum
The field list can be gotten by describing the feature class or table view you created the cursor from. (And of course, you can control which fields are included in the cursor by specifying them when creating the cursor.)

FieldObjects = arcpy.Describe(tbl).Fields 
FieldNames = [f.Name for f in FieldObjects] # field name strings in a list
Rows = arcpy.UpdateCursor(tbl)
for Row in Rows:
  for f in FieldNames:
    print f, str(Row.GetValue(f))
  print
0 Kudos
MarcNakleh
Regular Contributor
You can also make a call, for Tables, Shapes and Feature Classes, to the ListFields method directly.

FieldNames = [f.Name for f in arcpy.ListFields(tbl)] # field name strings in a list
Rows = arcpy.UpdateCursor(tbl)
for Row in Rows:
  for f in FieldNames:
    print f, str(Row.GetValue(f))

Interestingly, ESRI doesn't seem to list any differences between these two approaches. From the page:

Alternatively, the ListFields and ListIndexes functions can be used to create the same lists.
0 Kudos