Last active
March 24, 2020 19:39
-
-
Save jasonbot/3100423 to your computer and use it in GitHub Desktop.
Update cursor with dictionary rows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome. Thanks for the simple and effective dictionary.