Skip to main content

Having strings containing CJK characters left-, right-justified or centered conveniently.

Project description

cjkjust

Having strings containing CJK characters left-, right-justified or centered conveniently.

Installation

pip install cjkjust

Functions

  • is_wide(char) -> bool: returns whether a character char is wide
  • cjklen(string) -> int: returns the display width of a string containing CJK characters
  • cjkljust(string, width: int, fillbyte=' '): has string left-justified
  • cjkrjust(string, width: int, fillbyte=' '): has string right-justified
  • cjkcenter(string, width: int, fillbyte=' '): has string centered

Caveat: <TAB> in string ruins the print-out.

Examples

import cjkjust

# right-justify a column of strings
print(cjkjust.cjkrjust('hello 世界', 20))
print(cjkjust.cjkrjust('你好world', 20))
print(cjkjust.cjkrjust('again and again', 20))

Optional dependency

  • wcwidth: if installed, 0-width characters will also be well handled in cjkljust, cjkrjust, and cjkcenter. Caveat: installing wcwidth and explicitly set cjkjust.raises_on_indeterminate to True implies that ValueError will be raised if indeterminate-width-characters (e.g. <TAB>) is in string

It can be installed along with cjkjust by:

pip install cjkjust[allchars]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cjkjust-0.1.4.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

cjkjust-0.1.4-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page