python 简体和繁体的转换
python 简体和繁体的转换
在python处理字符串的时候,有的时候会用到简繁体之间的转换。
简繁体转换的工具很多,但是一直都没有一个完美的解决方案。
在这里介绍一个比较好用的简繁体转换工具,纯python编写,并且附上示例代码:
from langconv import *
# 转换繁体到简体
line = Converter('zh-hans').convert(line.decode('utf-8'))
line = line.encode('utf-8')
# 转换简体到繁体
line = Converter('zh-hant').convert(line.decode('utf-8'))
line = line.encode('utf-8')
备注:只需从网上下载langconv.py和zh_wiki.py,放在python代码所在目录即可。
相关内容
- 暂无相关文章
评论关闭