From 228db7856c33f209c426749b9025d01460888e5f Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 3 Aug 2021 20:22:27 +0200 Subject: [PATCH] Streamline file operations in convert() --- bin/translate.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bin/translate.py b/bin/translate.py index 54d311e9..d59d7a55 100644 --- a/bin/translate.py +++ b/bin/translate.py @@ -22,9 +22,7 @@ def convert(infile: str, outfile: str, cfg: str): """ converter = opencc.OpenCC(cfg) with open(infile, "r") as inf, open(outfile, "w+") as outf: - data = inf.readlines() - data = list(map(converter.convert, data)) - outf.writelines(data) + outf.write("\n".join(converter.convert(line) for line in inf)) print(f"Convert to {outfile}")