讲解Python如何把繁体转为简体

简介: Python把繁体字转为简体的方法

这里需要用到两个文件,从github下载: https://github.com/csdz/nstools/tree/master/zhtools
下载源文件:zh_wiki.py 和 langconv.py
转换函数:

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

a = tradition2simple2(u"無所謂")
print(a) 

# 结果
无所谓
相关文章
|
4天前
|
人工智能 测试技术 Linux
【Python 30天速成计划】1. 安装Python
【Python 30天速成计划】1. 安装Python
|
9月前
|
Python
|
9月前
|
Python
|
4天前
|
Linux iOS开发 MacOS
Python小姿势 - ## 安装Python
Python小姿势 - ## 安装Python
|
10月前
|
Python
Python - python处理word(python-docx)
Python - python处理word(python-docx)
187 0
|
9月前
|
Python
|
9月前
|
Python
|
9月前
|
Python
|
9月前
|
Linux Python Windows
Python | Python学习之unicode和utf8
Python | Python学习之unicode和utf8
|
11月前
|
Python