Does the arcpy.SearchCursor function support field indexing? In the sample script below, can I sent my cursor to loop through the values in the first field by setting an index to search the first field?
for x in arcpy.SearchCursor(filepath):
print x[0]
-
Could you explain why you might want to do this?blah238– blah2382013年08月30日 02:05:46 +00:00Commented Aug 30, 2013 at 2:05
2 Answers 2
My quick test below shows that the answer to your question is "No".
>>> for x in arcpy.SearchCursor(r"C:\polygeo\ArcTutor\Editing\Zion.gdb\Roads"):
... print x[0]
...
Runtime error
Traceback (most recent call last):
File "<string>", line 2, in <module>
TypeError: 'Row' object does not support indexing
However, if you are using ArcGIS for Desktop 10.1 or 10.2 then arcpy.da.SearchCursor provides the functionality that you seek.
>>> for x in arcpy.da.SearchCursor(r"C:\polygeo\ArcTutor\Editing\Zion.gdb\Roads","*"):
... print x[0]
...
172
173
174
175
It is not entirely clear why you want to do this, or which version of ArcGIS you are using, but you could do something like this at 10.0 if you are not at 10.1+:
fc = "some_feature_class.shp"
fieldnames = [field.name for field in arcpy.ListFields(fc)]
for row in arcpy.SearchCursor(fc):
print row.getValue(fieldnames[0])
Explore related questions
See similar questions with these tags.