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

python implements traditional and simplified Chinese character conversion

高洛峰
Release: 2016-10-18 10:56:16
Original
1497 people have browsed it

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')
Copy after login


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template