python繁體转为简体

需要从原作者的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 line


def tradition2simple2(line):
    # 将繁体转换成简体
    line = Converter('zh-hans').convert(line)
    line = line.encode('utf-8')
    return line

测试代码

print tradition2simple2(u"無所謂")

#輸出
无所谓

你可能感兴趣的:(Python)