python 将繁体转换成简体
#!/usr/bin/env python# -*- coding: utf-8 -*-from util.langconv import Converter #def cat_to_chs(sentence): #传入参数为列表"""将繁体转换成简体:param line::return:"""sentence =",".join(sentence)sentence =
·
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from util.langconv import Converter #
def cat_to_chs(sentence): #传入参数为列表
"""
将繁体转换成简体
:param line:
:return:
"""
sentence =",".join(sentence)
sentence = Converter('zh-hans').convert(sentence)
sentence.encode('utf-8')
return sentence.split(",")
def chs_to_cht(sentence):#传入参数为列表
"""
将简体转换成繁体
:param sentence:
:return:
"""
sentence =",".join(sentence)
sentence = Converter('zh-hant').convert(sentence)
sentence.encode('utf-8')
return sentence.split(",")
if __name__ == '__main__':
li_1 = ['鸡', '鸡', '虎', '牛', '猪', '虎', '兔']
li_2 = ['雞', '雞', '虎', '牛', '豬', '虎', '兔']
rest_fon = chs_to_cht(li_1) #简体转换成繁体
print("简体转换成繁体:{0}".format(rest_fon))
rest_chinese = cat_to_chs(li_2)
print("简体转换成简体:{0}".format(rest_chinese))
更多推荐
已为社区贡献1条内容
所有评论(0)