A simple package to processing CJK string
Project description
CJKStr -- A Simple Package for Processing CJK string
In Python, the string formatting function will treat a CJK characters as wide as a english letter.This make the result weired. For example:
print("1234567890" * 4)
a = "測試"
w = 10
print(f"{a:{w}s}|")
produce output as this:
1234567890123456789012345678901234567890
測試 |
The width is setting to 10 in the formatting string. Since the 2 Chinese characters occupies 2 more spaces, the bar is printed in position 13.
To avoid this problem, we need to know how many CJK Chinese characters in the string and resuce the width accorantly.
This package has only one funcion:
count_cjk_chars(s) # return number of chinese characters in string s
example
import cjkstr
print("1234567890" * 4)
a = "測試"
w = 10
print(f"{a:{w}s}|")
w = 10 - cjkstr.count_cjk_chars(a)
print(f"{a:{w}s}|")
ouput:
1234567890123456789012345678901234567890
測試 |
測試 |
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cjkstr-0.0.5.tar.gz.
File metadata
- Download URL: cjkstr-0.0.5.tar.gz
- Upload date:
- Size: 1.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a47d8d40e4458dacd7d93994862a3295d1edb20b75d841f01b1e186bcd46ba0e
|
|
| MD5 |
960e6b122483bd9f516781e905927a3f
|
|
| BLAKE2b-256 |
9e5d18f672ffefbf92a80b69cde9dca1b00e4b7789adc2b023c182ca4250f3f9
|
File details
Details for the file cjkstr-0.0.5-py3-none-any.whl.
File metadata
- Download URL: cjkstr-0.0.5-py3-none-any.whl
- Upload date:
- Size: 2.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76617d7ea9b721bf2fa392e6bbede2ad285eae256da6aeee0525511222a8b629
|
|
| MD5 |
23e60db4e1af4477bf87e03947910387
|
|
| BLAKE2b-256 |
649cc6945c6b7a44708577b63e280e7629ccf295a9ee232aef7fefe05ffe03e2
|