hanziconv package

Hanzi Converter 繁簡轉換器 | 繁简转换器

This module converts between simplified and traditional Chinese Characters. It consists of two parts:

  • a command line tool: hanzi-convert
  • a python library: hanziconv

Command Line Tool Usage:

$ ./hanzi-convert --help
usage: hanzi-convert [-h] [-o OUTFILE] [-s] [-v] infile

Simplified and Traditional Chinese Character Conversion
Version 0.3 (By Bernard Yue)

Converting to Traditional Hanzi by default with no -s flag

positional arguments:
  infile                filename | "-", corresponds to stdin

optional arguments:
  -h, --help            show this help message and exit
  -o OUTFILE, --output OUTFILE
                        filename to save output, stdout if omitted
  -s, --simplified      convert to simplified characters
  -v, --version         show program's version number and exit

Python Library Example:

>>> from hanziconv import HanziConv
>>> print(HanziConv.toSimplified('繁簡轉換器'))
繁简转换器
>>> print(HanziConv.toTraditional('繁简转换器'))
繁簡轉換器
>>> HanziConv.same('繁簡轉換器', '繁简转换器')
True
class hanziconv.HanziConv

Bases: object

This class supports hanzi (漢字) convention between simplified and traditional format

classmethod same(text1, text2)

Return True if text1 and text2 meant literally the same, False otherwise

Parameters:
  • text1 – string to compare to text2
  • text2 – string to compare to text1
Returns:

Truetext1 and text2 are the same in meaning, False – otherwise

>>> from hanziconv import HanziConv
>>> print(HanziConv.same('繁简转换器', '繁簡轉換器'))
True
classmethod toSimplified(text)

Convert text to simplified character string. Assuming text is traditional character string

Parameters:text – text to convert
Returns:converted UTF-8 characters
>>> from hanziconv import HanziConv
>>> print(HanziConv.toSimplified('繁簡轉換器'))
繁简转换器
classmethod toTraditional(text)

Convert text to traditional character string. Assuming text is simplified character string

Parameters:text – text to convert
Returns:converted UTF-8 characters
>>> from hanziconv import HanziConv
>>> print(HanziConv.toTraditional('繁简转换器'))
繁簡轉換器

Table Of Contents

This Page