diff --git a/examples/create_eqpt_sheet.py b/examples/create_eqpt_sheet.py index f1e247f7..b0f7b4ca 100644 --- a/examples/create_eqpt_sheet.py +++ b/examples/create_eqpt_sheet.py @@ -70,7 +70,7 @@ def read_excel(input_filename): def create_eqt_template(links,nodes, links_by_src , links_by_dest, input_filename): output_filename = f'{input_filename[:-4]}_eqpt_sheet.txt' - with open(output_filename,'w') as my_file : + with open(output_filename, 'w', encoding='utf-8') as my_file: # print header similar to excel my_file.write('OPTIONAL\n\n\n\ \t\tNode a egress amp (from a to z)\t\t\t\t\tNode a ingress amp (from z to a) \ diff --git a/examples/path_requests_run.py b/examples/path_requests_run.py index c72e3c2e..ebb20123 100755 --- a/examples/path_requests_run.py +++ b/examples/path_requests_run.py @@ -74,7 +74,7 @@ def load_requests(filename,eqpt_filename): logger.info('Automatically converting requests from XLS to JSON') json_data = convert_service_sheet(filename,eqpt_filename) else: - with open(filename) as f: + with open(filename, encoding='utf-8') as f: json_data = loads(f.read()) return json_data diff --git a/examples/write_path_jsontocsv.py b/examples/write_path_jsontocsv.py index 1a7584b3..b7b50dd2 100644 --- a/examples/write_path_jsontocsv.py +++ b/examples/write_path_jsontocsv.py @@ -26,8 +26,8 @@ parser.add_argument('eqpt_filename', nargs='?', type = Path, default=Path(__file if __name__ == '__main__': args = parser.parse_args() - with open(args.output_filename,"w") as file : - with open(args.filename) as f: + with open(args.output_filename, 'w', encoding='utf-8') as file: + with open(args.filename, encoding='utf-8') as f: print(f'Reading {args.filename}') json_data = loads(f.read()) equipment = load_equipment(args.eqpt_filename) diff --git a/gnpy/core/convert.py b/gnpy/core/convert.py index 38d25217..89c5d23d 100755 --- a/gnpy/core/convert.py +++ b/gnpy/core/convert.py @@ -220,7 +220,7 @@ def convert_file(input_filename, filter_region=[]): full_input_filename = str(input_filename) split_filename = [full_input_filename[0:len(full_input_filename)-len(suffix_filename)] , suffix_filename[1:]] output_json_file_name = split_filename[0]+'.json' - with open(output_json_file_name,'w') as edfa_json_file: + with open(output_json_file_name, 'w', encoding='utf-8') as edfa_json_file: edfa_json_file.write(dumps(data, indent=2)) return output_json_file_name diff --git a/gnpy/core/equipment.py b/gnpy/core/equipment.py index 6f2a0204..41bf867f 100644 --- a/gnpy/core/equipment.py +++ b/gnpy/core/equipment.py @@ -43,13 +43,13 @@ class Amp(AmpBase): @classmethod def from_advanced_json(cls, filename, **kwargs): - with open(filename) as f: + with open(filename, encoding='utf-8') as f: json_data = load(f) return cls(**{**kwargs, **json_data, 'type_def':None, 'nf_model':None}) @classmethod def from_default_json(cls, filename, **kwargs): - with open(filename) as f: + with open(filename, encoding='utf-8') as f: json_data = load(f) type_variety = kwargs['type_variety'] type_def = kwargs.get('type_def', 'variable_gain') #default compatibility with older json eqpt files diff --git a/gnpy/core/utils.py b/gnpy/core/utils.py index 96d1716f..05c46cf3 100644 --- a/gnpy/core/utils.py +++ b/gnpy/core/utils.py @@ -18,13 +18,13 @@ from scipy import constants def load_json(filename): - with open(filename, 'r') as f: + with open(filename, 'r', encoding='utf-8') as f: data = json.load(f) return data def save_json(obj, filename): - with open(filename, 'w') as f: + with open(filename, 'w', encoding='utf-8') as f: json.dump(obj, f, indent=2) def write_csv(obj, filename): @@ -55,7 +55,7 @@ def write_csv(obj, filename): result_category 2 ... """ - with open(filename, 'w') as f: + with open(filename, 'w', encoding='utf-8') as f: w = writer(f) for data_key, data_list in obj.items(): #main header diff --git a/tests/compare.py b/tests/compare.py index d208969b..1b5ed9e0 100644 --- a/tests/compare.py +++ b/tests/compare.py @@ -105,16 +105,16 @@ def encode_sets(obj): if __name__ == '__main__': args = parser.parse_args() - with open(args.expected_output) as f: + with open(args.expected_output, encoding='utf-8') as f: expected = load(f) - with open(args.actual_output) as f: + with open(args.actual_output, encoding='utf-8') as f: actual = load(f) result = COMPARISONS[args.comparison](expected, actual) if args.output: - with open(args.output, 'w') as f: + with open(args.output, 'w', encoding='utf-8') as f: dump(result, f, default=encode_sets, indent=2) else: print(str(result)) diff --git a/tests/test_parser.py b/tests/test_parser.py index dbfe94b9..751bcb38 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -37,11 +37,11 @@ def test_excel_json_generation(xls_input, expected_json_output): convert_file(xls_input) actual_json_output = xls_input.with_suffix('.json') - with open(actual_json_output) as f: + with open(actual_json_output, encoding='utf-8') as f: actual = load(f) unlink(actual_json_output) - with open(expected_json_output) as f: + with open(expected_json_output, encoding='utf-8') as f: expected = load(f) results = compare_networks(expected, actual) @@ -65,11 +65,11 @@ def test_excel_service_json_generation(xls_input, expected_json_output): convert_service_sheet(xls_input, eqpt_filename) actual_json_output = f'{str(xls_input)[:-4]}_services.json' - with open(actual_json_output) as f: + with open(actual_json_output, encoding='utf-8') as f: actual = load(f) unlink(actual_json_output) - with open(expected_json_output) as f: + with open(expected_json_output, encoding='utf-8') as f: expected = load(f) results = compare_services(expected, actual)