The following code reads a file from our Natural Earth dataset and prints its dictionary keys:
In: import fiona c = fiona.open(r"C:\data\gdal\NE\ 110m_cultural\ne_110m_admin_1_states_provinces.shp") rec = next(iter(c)) rec.keys()Out: dict_keys(['type', 'id', 'geometry', 'properties'])
Using the data pretty-print (pprint) library that is part of Python's standard library, we can print the corresponding values to the keys of the first feature from our dataset:
In: import pprint pprint.pprint(rec['type']) pprint.pprint(rec['id']) pprint.pprint(rec['properties']) pprint.pprint(rec['geometry'])Out: 'Feature' '0' OrderedDict([('adm1_code', 'USA-3514'), ('diss_me', 3514), ('iso_3166_2', 'US-MN'), ('wikipedia', 'http://en.wikipedia.org/wiki/Minnesota'), ...