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
(only for building)
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 MIT 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.tar.gz
(35.5 kB
view details)
File details
Details for the file cwcwidth-0.1.tar.gz
.
File metadata
- Download URL: cwcwidth-0.1.tar.gz
- Upload date:
- Size: 35.5 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 | fc9492a88fe263e598866b17fb0da3dc905ed2f0e2efebc410d6c385db59d9f0 |
|
MD5 | d6f2727c765daa8c740b35169fb44838 |
|
BLAKE2b-256 | 614cb300c768ac6309de569fb33cd9b25b9bf9286de98816d8dd5911e8adb513 |