读取txt,将繁体字转换为简体字
import zhconv
def traditional_to_simplified(text):
# 调用convert函数将繁体字转换为简体字
simplified_text = zhconv.convert(text, 'zh-hans')
return simplified_text
path_txt=r"C:\Users\xueshifeng\Desktop\笔记语音附件_20240112114522607 (Transcribed on 01-Feb-2024 10-30-04).txt"
#读取txt
file = open(path_txt, 'r',encoding='utf-8')
text = file.read()
file.close()
text_res=traditional_to_simplified(text)
#写入txt
path_txt=r"C:\Users\xueshifeng\Desktop\res.txt"
# 打开或创建一个文本文件对象
file = open(path_txt, 'w')
file.write(text_res)
# 关闭文件对象
file.close()