Created
July 12, 2012 19:37
-
-
Save jasonbot/3100403 to your computer and use it in GitHub Desktop.
Get namedtuples instead of lists from an arcpy.da SearchCursor
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
import collections | |
def rows_as_namedtuples(cursor): | |
col_tuple = collections.namedtuple('Row', cursor.fields) | |
for row in cursor: | |
yield col_tuple(*row) | |
with arcpy.da.SearchCursor(r'c:\data\world.gdb\world_cities', '*') as sc: | |
for row in rows_as_namedtuples(sc): | |
print sc.CITY_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
there's also
rename=True
at the cost of some name predictability. Both rename methods in concert could be useful.