mirror of
https://github.com/Vonng/ddia.git
synced 2024-12-06 15:20:12 +08:00
Streamline file operations in convert()
This commit is contained in:
parent
f744e6d102
commit
228db7856c
@ -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}")
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user