Streamline file operations in convert()

This commit is contained in:
Christian Clauss 2021-08-03 20:22:27 +02:00 committed by GitHub
parent f744e6d102
commit 228db7856c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,9 +22,7 @@ def convert(infile: str, outfile: str, cfg: str):
""" """
converter = opencc.OpenCC(cfg) converter = opencc.OpenCC(cfg)
with open(infile, "r") as inf, open(outfile, "w+") as outf: with open(infile, "r") as inf, open(outfile, "w+") as outf:
data = inf.readlines() outf.write("\n".join(converter.convert(line) for line in inf))
data = list(map(converter.convert, data))
outf.writelines(data)
print(f"Convert to {outfile}") print(f"Convert to {outfile}")