python繁體转为简体

来源:互联网 发布:叮当在线客服软件 编辑:程序博客网 时间:2024/05/29 16:28

需要从原作者的github上下载两个源文件:zh_wiki.py 和 langconv.py

地址:https://github.com/csdz/nstools/tree/master/zhtools

转换函数:

from langconv import *def tradition2simple(line):    # 将繁体转换成简体    line = Converter('zh-hans').convert(line.decode('utf-8'))    line = line.encode('utf-8')    return linedef tradition2simple2(line):    # 将繁体转换成简体    line = Converter('zh-hans').convert(line)    line = line.encode('utf-8')    return line

测试代码

print tradition2simple2(u"無所謂")#輸出无所谓
原创粉丝点击