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 characterchar
is widecjklen(string) -> int
: returns the display width of astring
containing CJK characterscjkljust(string, width: int, fillbyte=' ')
: hasstring
left-justifiedcjkrjust(string, width: int, fillbyte=' ')
: hasstring
right-justifiedcjkcenter(string, width: int, fillbyte=' ')
: hasstring
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 incjkljust
,cjkrjust
, andcjkcenter
. Caveat: installingwcwidth
and explicitly setcjkjust.raises_on_indeterminate
toTrue
implies thatValueError
will be raised if indeterminate-width-characters (e.g.<TAB>
) is instring
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)