Home > Article > Backend Development > python implements traditional and simplified Chinese character conversion
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')