网络编程
位置:首页>> 网络编程>> Python编程>> Python实现繁體转为简体的方法示例

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

作者:Tangzongyu123  发布时间:2022-08-10 01:49:58 

标签:Python,繁體,简体

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

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

或者从github下载: 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"無所謂")

#輸出
无所谓

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

PS:这里再为大家推荐几款功能相似的在线工具供大家参考:

中文繁体字简体字转换(繁简转换)工具:
http://tools.jb51.net/transcoding/convertzh

在线自动排版与转换工具:
http://tools.jb51.net/aideddesign/txt_beaut

在线文字/文本排版/转换工具(脚本之家加强版):
http://tools.jb51.net/aideddesign/jb51_paiban

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

来源:https://blog.csdn.net/Tangzongyu123/article/details/77115949

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com