From 23d4554ec05d6cf5b35960052de8f324b7e0ec86 Mon Sep 17 00:00:00 2001 From: thomwolf Date: Wed, 17 Apr 2019 14:48:34 +0200 Subject: [PATCH] is python 2 happy now --- pytorch_pretrained_bert/file_utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pytorch_pretrained_bert/file_utils.py b/pytorch_pretrained_bert/file_utils.py index e7e1714f97..17bdd258ea 100644 --- a/pytorch_pretrained_bert/file_utils.py +++ b/pytorch_pretrained_bert/file_utils.py @@ -242,7 +242,10 @@ def get_from_cache(url, cache_dir=None): meta = {'url': url, 'etag': etag} meta_path = cache_path + '.json' with open(meta_path, 'w') as meta_file: - meta_file.write(json.dumps(meta, indent=4)) + output_string = json.dumps(meta) + if sys.version_info[0] == 2 and isinstance(output_string, str): + output_string = unicode(output_string, 'utf-8') # The beauty of python 2 + meta_file.write(output_string) logger.info("removing temp file %s", temp_file.name)