def mkdict(row): """Turn a geocoder response row into a well-formed dict""" d = dict(zip(geocoder_header, row)) if len(row) > 3: try: try: d['lat'], d['lon'] = d['latlon'].split(',') except ValueError as e: d['lat'], d['lon'] = '','' d['tract_geoid'] = str(Tract( int(d['state_fips']), int(d['county_fips']), int(d['tract_fips']) )) try: del d['latlon'] except Exception as e: pass except Exception as e: # These appear to be errors associated with quote characters in the addresses, like # 366426709,"8430 I AVENUE""", HESPERIA, CA," 92345""",No_Match. There aren't many of # them, but they are a problem print("ERROR for ", row, e, file=sys.stderr) d['input_address'] = '' d['match'] = 'Parse Error' return d