Great answers. But it looks as if the row
itself was not shown in the answers.
Another thing that is good to know is that when a single field is supplied, a singleton tuple is returned (row
in this case):
with arcpy.da.SearchCursor(fc,"PROPERTY_ID") as search_cur:
for row in search_cur:
print row
break
>>> (5001,)
It's easy to understand that this is a singleton tuple by looking at the trailing comma it has. By the way, you don't need to supply a list of fields when you have just one field. This line would also work for you:
cursor = arcpy.da.SearchCursor("alaska","PERIMETER",'"PERIMETER"=0.224')
Please use the with
statement when constructing the cursors; this will handle cleaning up and deleting the objects when they've been used and are no longer needed. Take a look at the Esri samples here and other samples here.
A handy way to access all of the features within a feature class without using the for
iteration, is a list comprehension:
feats = [feat for feat in arcpy.da.SearchCursor(fc,"PROPERTY_ID")]
#printing first three elements
print feats[:3]
>>> [(5001,), (5002,), (1003,)]
The feats
can be referred to as a list of singleton tuples. Fairly often, you would like to get a list of those values without having tuples at all. Again, list comprehension comes in very handy.
feats = [feat[0] for feat in arcpy.da.SearchCursor(fc,"PROPERTY_ID")]
#printing first three elements
print feats[:3]
>>> [5001, 5002, 1003]
The feat[0]
returns a first item in the singleton tuple.
row[0]
refers to the first item in a list (in this case a list of fields). Even though you only have one fieldPERIMETER
, it's still a list. If you had more fields you could userow[1]
,row[2]
etc. – Midavalo♦ Mar 22 '16 at 5:34[]
operator. It is a very common idiom in programming languages/scripts to access objects/values stored in lists, vectors, maps, etc. Getting the vocab will help you greatly in the future when searching for answers. – RomaH Mar 22 '16 at 15:52