i am trying to use the Search Cursor in my program without specifying "da", like so:
`
for row in arcpy.SearchCursor(layer):
print(row["field_name"])
`
I used to be able to do something like this in ArcGIS 10. Has this way of using the cursor been deprecated in ArcGIS Pro?
It has been superseded by the arcpy.da functionality, without it is only possible in legacy scripts, here's the documentation page that shows this: https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/searchcursor.htm
Cody
Although ArcPy Data Access (da) cursors are newer, and better in nearly every way, Esri continues to maintain the original cursors for backwards compatibility. You should be able to run old code and even write new code using the old cursors, so are you encountering errors? If so, what are the errors?
The parameters and parameter orders are different for arcpy.da.SearchCursor and the legacy arcpy.SearchCursor, but I see I think if you want to follow your previous coding style you could write a legacy SearchCursor like so:
for row in arcpy.SearchCursor(dataset="layer"):
print(row.getValue("OBJECTID")
# note that it seems you must use row.getValue("field") rather than row["field"] like in your example
...
If you want to use the equivalent code with arcpy.da.SearchCursor must specify fields that you want to return values for. This is different from the legacy SearchCursor. I didn't even realize the legacy method allowed you to not specify fields and instead row.getValue("field"). So that's a big change if you did not previously use cursors this way:
for row in arcpy.da.SearchCursor(in_table="layer", field_names=["OBJECTID", "other_field"]):
print(row[0])
print(row[1])
...
the more common practice is to use this format for cursors. If I'm not mistaken, this is more critical for UpdateCursor since you have to reference the cursor object to perform an update or delete method, e.g. cursor.updateRow(row):
with arcpy.da.SearchCursor(in_table="layer", field_names=["OBJECTID", "other_field"]) as cursor:
for row in cursor:
print(row[0])
print(row[1])
...