Created
May 10, 2022 07:36
-
-
Save Keycatowo/fe9ab5a012d91e7eef1fd366288ba500 to your computer and use it in GitHub Desktop.
使用OpenCC用來轉換簡體繁體
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# %% | |
from opencc import OpenCC | |
mode_config = { | |
"簡體->繁體":"s2t", | |
"簡體->繁體台灣":"s2tw", | |
"簡體->繁體台灣(含慣用詞)": "s2twp" | |
} | |
MODE = "簡體->繁體台灣(含慣用詞)" | |
FILE_INPUT = "data/input.txt" | |
FILE_OUTPUT = "data/output.txt" | |
#%% | |
if __name__ == "__main__": | |
cc = OpenCC(mode_config[MODE]) | |
# 輸入 | |
with open(FILE_INPUT, "r", encoding="utf-8") as f: | |
text = f.read() | |
# 輸出 | |
with open(FILE_OUTPUT, "w", encoding="utf-8") as f: | |
f.write(cc.convert(text)) | |
# %% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment