1

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]
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Aug 28, 2013 at 20:37
1
  • Could you explain why you might want to do this? Commented Aug 30, 2013 at 2:05

2 Answers 2

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
answered Aug 29, 2013 at 6:41
1

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])
answered Oct 2, 2013 at 2:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.