Home  >  Article  >  Backend Development  >  python implements traditional and simplified Chinese character conversion

python implements traditional and simplified Chinese character conversion

高洛峰
高洛峰Original
2016-10-18 10:56:161466browse

Requirement: Convert Chinese strings into Traditional Chinese and Simplified Chinese;

Idea: Introduce the Simplified and Traditional Chinese processing library. Interested students can study the internal implementation, which is all written in Python


1. Download zh_wiki. py and langconv


zh_wiki.py:https://github.com/skydark/nstools/blob/master/zhtools/zh_wiki.py


langconv.py:https://github.com/ skydark/nstools/blob/master/zhtools/langconv.py


Download langconv.py and zh_wiki.py and put them in the directory where the python code is located


2. Code examples

# -*- coding:utf-8 -*-
  
    from langconv import *
  
# 转换繁体到简体
line = Converter('zh-hans').convert(line.decode('utf-8'))
line = line.encode('utf-8')
  
# 转换简体到繁体
line = Converter('zh-hant').convert(line.decode('utf-8'))
line = line.encode('utf-8')


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn