mojimoji

0.0.13 · active · verified Thu Apr 16

mojimoji is a Cython-based Python library designed for fast conversion between Japanese half-width (hankaku) and full-width (zenkaku) characters. The current version is 0.0.13, and it receives updates for bug fixes and Python version compatibility, though major feature releases are infrequent.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import the `mojimoji` library and use its primary conversion functions, `zen_to_han` and `han_to_zen`, including an example of selective conversion using keyword arguments.

import mojimoji

# Convert full-width to half-width characters
zenkaku_text = 'アイウabc012'
hankaku_text = mojimoji.zen_to_han(zenkaku_text)
print(f"'{zenkaku_text}' (full-width) -> '{hankaku_text}' (half-width)")

# Convert half-width to full-width characters
hankaku_text_2 = 'アイウabc012'
zenkaku_text_2 = mojimoji.han_to_zen(hankaku_text_2)
print(f"'{hankaku_text_2}' (half-width) -> '{zenkaku_text_2}' (full-width)")

# Selective conversion: convert only digits to half-width
selective_zenkaku = '漢字123ひらがなABC'
selective_hankaku = mojimoji.zen_to_han(selective_zenkaku, kana=False, ascii=False)
print(f"'{selective_zenkaku}' (selective zen->han) -> '{selective_hankaku}'")

view raw JSON →