add encoding="utf-8"

pull/367/head
Adonis Pujols 2021-02-11 05:26:06 -05:00 committed by Eren Gölge
parent ffceccb021
commit 89b7f01534
1 changed files with 3 additions and 3 deletions

View File

@ -22,7 +22,7 @@ class AttrDict(dict):
def read_json_with_comments(json_path): def read_json_with_comments(json_path):
# fallback to json # fallback to json
with open(json_path, "r") as f: with open(json_path, "r", encoding = "utf-8") as f:
input_str = f.read() input_str = f.read()
# handle comments # handle comments
input_str = re.sub(r'\\\n', '', input_str) input_str = re.sub(r'\\\n', '', input_str)
@ -40,7 +40,7 @@ def load_config(config_path: str) -> AttrDict:
ext = os.path.splitext(config_path)[1] ext = os.path.splitext(config_path)[1]
if ext in (".yml", ".yaml"): if ext in (".yml", ".yaml"):
with open(config_path, "r") as f: with open(config_path, "r", encoding = "utf-8") as f:
data = yaml.safe_load(f) data = yaml.safe_load(f)
else: else:
data = read_json_with_comments(config_path) data = read_json_with_comments(config_path)
@ -61,7 +61,7 @@ def copy_model_files(c, config_file, out_path, new_fields):
""" """
# copy config.json # copy config.json
copy_config_path = os.path.join(out_path, 'config.json') copy_config_path = os.path.join(out_path, 'config.json')
config_lines = open(config_file, "r").readlines() config_lines = open(config_file, "r", encoding = "utf-8").readlines()
# add extra information fields # add extra information fields
for key, value in new_fields.items(): for key, value in new_fields.items():
if isinstance(value, str): if isinstance(value, str):