From f34efbf27c9b0090ec9d4e69ceafa717a7032c84 Mon Sep 17 00:00:00 2001 From: Luis Gonzalez Date: Thu, 9 Nov 2023 12:28:00 -0500 Subject: [PATCH] fix utf encoding on geography.py (#923) --- scripts/un/sdg/geography.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/un/sdg/geography.py b/scripts/un/sdg/geography.py index ce551bc0e9..e8d6706724 100644 --- a/scripts/un/sdg/geography.py +++ b/scripts/un/sdg/geography.py @@ -97,7 +97,7 @@ def get_sdg2type(file): Map of SDG code -> SDG type. ''' sdg2type = {} - with open(file) as f: + with open(file, encoding='utf-8') as f: reader = csv.DictReader(f) for row in reader: sdg2type[row['GEOGRAPHY_CODE']] = row['GEOGRAPHY_TYPE'] @@ -140,7 +140,7 @@ def get_un2dc_curated(file): Map of UN code -> curated Node. ''' un2dc_curated = {} - with open(file) as f: + with open(file, encoding='utf-8') as f: reader = csv.DictReader(f) for row in reader: @@ -204,8 +204,8 @@ def write_un_places(input_geos, output, sdg2type, un2sdg, un2dc_curated): ''' un2dc_generated = {} new_subjects = [] - with open(input_geos) as f_in: - with open(output, 'w') as f_out: + with open(input_geos, encoding='utf-8') as f_in: + with open(output, 'w', encoding='utf-8') as f_out: reader = csv.DictReader(f_in) for row in reader: subject = row['subject_id'] @@ -288,7 +288,7 @@ def write_un_containment(output, containment, new_subjects): new_subjects: List of Nodes for new places. ''' - with open(output, 'w') as f: + with open(output, 'w', encoding='utf-8') as f: for s in sorted(containment): c = '' for o in containment[s]: @@ -323,7 +323,7 @@ def write_place_mappings(output, sdg2un, un2dc_curated, un2dc_generated): un2dc_curated: Map of UN code -> curated Node. un2dc_generated: Map of UN code -> generated Node. ''' - with open(output, 'w') as f: + with open(output, 'w', encoding='utf-8') as f: writer = csv.DictWriter(f, fieldnames=['sdg', 'dcid']) writer.writeheader() for code in sorted(sdg2un):