Skip to content

Instantly share code, notes, and snippets.

@jasonbot
Last active March 24, 2020 19:39
Show Gist options
  • Save jasonbot/3100423 to your computer and use it in GitHub Desktop.
Save jasonbot/3100423 to your computer and use it in GitHub Desktop.
Update cursor with dictionary rows
def rows_as_update_dicts(cursor):
colnames = cursor.fields
for row in cursor:
row_object = dict(zip(colnames, row))
yield row_object
cursor.updateRow([row_object[colname] for colname in colnames])
with arcpy.da.UpdateCursor(r'c:\data\world.gdb\world_cities', ['CITY_NAME']) as sc:
for row in rows_as_update_dicts(sc):
row['CITY_NAME'] = row['CITY_NAME'].title()
print "Updating city name to {}".format(row['CITY_NAME'])
@paulinamarczak
Copy link

Awesome. Thanks for the simple and effective dictionary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment