From bf55856f94904a79b1186d33aaa27c067afbde32 Mon Sep 17 00:00:00 2001 From: Dustin Pianalto Date: Wed, 9 May 2018 16:44:25 -0800 Subject: [PATCH] Try utf-16 if utf-8 fails --- exts/imports/process_files.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/exts/imports/process_files.py b/exts/imports/process_files.py index 89b19c3..d032e4f 100644 --- a/exts/imports/process_files.py +++ b/exts/imports/process_files.py @@ -118,10 +118,11 @@ def process_files(z) -> (ConfigParser, ConfigParser, list): except UnicodeDecodeError as e: print(e) try: - with open(f'{path}{filename}', 'w+b') as file: + with open(f'{path}{filename}', 'rb') as file: contents = file.read() - file.write(contents.decode('utf-16-le').encode('utf-8')) - with open(f'{path}{filename}', encoding='utf-8') as file: + with open(f'{path}utf8{filename}', 'wb') as f: + f.write(contents.decode('utf-16-le').encode('utf-8')) + with open(f'{path}utf8{filename}', encoding='utf-8') as file: dino_data[filename] = process_file(file, 'dino.ini') except UnicodeDecodeError as e: print(e)