Merge pull request #119 from cclauss/patch-1

Streamline file operations in convert()
This commit is contained in:
Feng Ruohang 2021-08-09 21:29:49 +08:00 committed by GitHub
commit ef60741b6b
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}")