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

yipeiwu_com7年前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

在线文字/文本排版/转换工具(【听图阁-专注于Python设计】加强版):
http://tools.jb51.net/aideddesign/jb51_paiban

更多关于Python相关内容感兴趣的读者可查看本站专题:《Python编码操作技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总》

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

相关文章

python中图像通道分离与合并实例

我就废话不多说了,直接上代码吧! import cv2 img = cv2.imread("1.jpg") b, g, r = cv2.split(img)  #分离函...

python求最大值最小值方法总结

python求最大值最小值方法总结

方法一(常规): 代码: count = int(input('输入数据个数:\n')) a = 1 while a <= count: num = int(input(...

Python中datetime常用时间处理方法

常用时间转换及处理函数: import datetime # 获取当前时间 d1 = datetime.datetime.now() print d1 # 当前时间加上半小时 d2...

浅谈Tensorflow由于版本问题出现的几种错误及解决方法

1、AttributeError: 'module' object has no attribute 'rnn_cell' S:将tf.nn.rnn_cell替换为tf.contrib....

python使用selenium实现批量文件下载

python使用selenium实现批量文件下载

背景 实现需求:批量下载联想某型号的全部驱动程序。 一般在做网络爬虫的时候,都是保存网页信息为主,或者下载单个文件。当涉及到多文件批量下载的时候,由于下载所需时间不定,下载的文件名不定,...