# List records using search cursor (snippet) table_to_select_from = r"/home/engine/scripts/connections/ARCSDE101-DEV1-PG-DC-GDRS_DEV-GDRS-DEFAULT.sde\gdrs_dev.gdrs.test_arcpy_da" field_list = ["id", "field1", "field2", "field3", "field4"] try: with arcpy.da.SearchCursor(table_to_select_from, field_list) as search_cursor: for row in search_cursor: print("{0}, {1}, {2}, {3}, {4}".format(row[0], row[1], row[2], row[3], row[4])) except Exception as err: print(err) exit(1)
# Insert record (snippet): table_to_insert_into = r"/home/engine/scripts/connections/ARCSDE101-DEV1-PG-DC-GDRS_DEV-GDRS-DEFAULT.sde\gdrs_dev.gdrs.test_arcpy_da" field_list = ["field1", "field2", "field3", "field4"] values_list = ["Test arcpy.da.insertRow", "Hello World!", 10, "2013-03-23"] try: with arcpy.da.InsertCursor(table_to_insert_into, field_list) as insert_cursor: insert_cursor.insertRow(values_list) except Exception as err: print(err) exit(1)
table_to_update = r"/home/engine/scripts/connections/ARCSDE101-DEV1-PG-DC-GDRS_DEV-GDRS-DEFAULT.sde\gdrs_dev.gdrs.test_arcpy_da" field_list = ["field3"] try: with arcpy.da.UpdateCursor(table_to_update, field_list) as update_cursor: for row in update_cursor: row[0] = row[0] * 2 update_cursor.updateRow(row) del row, update_cursor except Exception as err: print(err)
Solved! Go to Solution.
try: arcpy.da.UpdateCursor(table_to_update, ["*"]) except Exception as err: print(err)
try: with arcpy.da.UpdateCursor(table_to_update, ["*"]) as update_cursor: pass except Exception as err: print(err)
try: with arcpy.da.UpdateCursor(table_to_update, ["*"]) as update_cursor: for row in update_cursor: pass except Exception as err: print(err)
updateRows = arcpy.da.UpdateCursor(myTbl, ["MY_FIELD"]) for updateRow in updateRows: fieldValue = updateRow[0] field value = fieldValue + 10 updateRows.updateRow(updateRow) del updateRow, updateRows
updateRows = arcpy.da.UpdateCursor(myTbl, ["MY_FIELD"]) for updateRow in updateRows: fieldValue = updateRow[updateRows.fields.index("MY_FIELD")] field value = fieldValue + 10 updateRows.updateRow(updateRow) del updateRow, updateRows