From c91df97e25f569814efd66250bad80235e102b38 Mon Sep 17 00:00:00 2001 From: Fabian Wunsch Date: Sat, 9 Apr 2022 23:30:11 +0200 Subject: [PATCH] More beautiful way of fixing this --- tools/formatter.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/formatter.py b/tools/formatter.py index b3e712a5..7437ebba 100644 --- a/tools/formatter.py +++ b/tools/formatter.py @@ -2,6 +2,7 @@ import re import json +import io """ Examples: @@ -263,11 +264,11 @@ def per_line_entries(entries: list): """ Returns a string of all the entries, with every entry in one line. """ - out = "[\r\n" + out = "[\n" for entry in entries: if entry: - out += json.dumps(entry, ensure_ascii=False) + ",\r\n" - out = out[:-2] + "\r\n]" + out += json.dumps(entry, ensure_ascii=False) + ",\n" + out = out[:-2] + "\n]" return out def format_all(entry: dict, silent=False): @@ -326,8 +327,8 @@ def go(path): print(f"{len(entries)} checked.") - with open(path, "wb") as f2: - f2.write(per_line_entries(entries).encode(encoding='utf-8')) + with io.open(path, "w", encoding='utf-8', newline='\r\n') as f2: + f2.write(per_line_entries(entries)) print("Writing completed. All done.")