Python bindings for wc(s)width
Project description
Python bindings for wc(s)width
cwcwidth
provides Python bindings for wcwidth
and wcswidth
functions defined in POSIX.1-2001
and POSIX.1-2008 based on Cython. These functions compute the printable
length of a unicode character/string on a terminal. The module provides the same functions as
wcwidth and its behavior is compatible.
On systems not conforming to POSIX.1-2001 and POSIX.1-2008, Markus Kuhn's implementation is used to provide the functionality.
Dependencies
Cython >= 0.28
(optional, only for building). If Cython is not available, the C files are not regenerated from their source.
Quick installation guide
cwcwidth
can be installed via pip
:
pip install cwcwidth
or by running:
python3 setup.py install
Usage
import cwcwidth
cwcwidth.wcwidth("a") # 1
cwcwidth.wcswidth("コ") # 2
cwcwidth.wcswidth("コンニチハ, セカイ!") # 19
Comparison with wcwidth
>>> import wcwidth, cwcwidth, timeit
>>> timeit.timeit(lambda: wcwidth.wcswidth("コンニチハ, セカイ!"))
19.14463168097427
>>> timeit.timeit(lambda: cwcwidth.wcswidth("コンニチハ, セカイ!"))
0.16294104099506512
License
The code is licensed under the Expat license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cwcwidth-0.1.1.tar.gz
(35.7 kB
view details)
File details
Details for the file cwcwidth-0.1.1.tar.gz
.
File metadata
- Download URL: cwcwidth-0.1.1.tar.gz
- Upload date:
- Size: 35.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 042cdf80d80a836935f700d8e1c34270f82a627fc07f7b5ec1e8cec486e1d755 |
|
MD5 | 99f8656b490f5cd8e71cdd01f2ab8f38 |
|
BLAKE2b-256 | 773a7674069b8b8a40b1e25eea33c3a228b8d57c24f3e286e6de1825e0e02437 |