脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Python实现繁體转为简体的方法示例

Python实现繁體转为简体的方法示例

2021-05-03 00:53Tangzongyu123 Python

这篇文章主要介绍了Python实现繁體转为简体的方法,涉及Python编码转换相关操作技巧,需要的朋友可以参考下

本文实例讲述了Python实现繁體转为简体的方法。分享给大家供大家参考,具体如下:

这里需要用到两个文件,可以点击此处本站下载源文件:zh_wiki.py  和 langconv.py

或者从github下载: https://github.com/csdz/nstools/tree/master/zhtools

转换函数:

?
1
2
3
4
5
6
7
8
9
10
11
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

测试代码

?
1
print tradition2simple2(u"無所謂")

#輸出
无所谓

注:这里需要安装psycopg模块,可点击https://www.lfd.uci.edu/~gohlke/pythonlibs/选择对应的版本进行安装。

希望本文所述对大家Python程序设计有所帮助。

原文链接:https://blog.csdn.net/Tangzongyu123/article/details/77115949

延伸 · 阅读

精彩推荐