Message145497
> There might be something you can steal from ...
I don't think that Python should reinvent the wheel. We should just reuse wcswidth().
Here is a simple patch exposing wcswidth() function as locale.width().
Example:
>>> import locale
>>> text = '\u3042\u3044\u3046\u3048\u304a'
>>> len(text)
5
>>> locale.width(text)
10
>>> locale.width(' ')
1
>>> locale.width('\U0010abcd')
1
>>> locale.width('\uDC80')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
locale.Error: the string is not printable
>>> locale.width('\U0010FFFF')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
locale.Error: the string is not printable
I don't think that we need locale.width() on Windows because its console has already bigger issues with Unicode: see issue #1602. If you want to display correctly non-ASCII characters on Windows, just avoid the Windows console and use a graphical widget. |
|
Date |
User |
Action |
Args |
2011-10-14 01:28:35 | vstinner | set | recipients:
+ vstinner, loewis, ezio.melotti, inigoserna, zeha, Nicholas.Cole, tchrist |
2011-10-14 01:28:35 | vstinner | set | messageid: <1318555715.45.0.571457855494.issue12568@psf.upfronthosting.co.za> |
2011-10-14 01:28:34 | vstinner | link | issue12568 messages |
2011-10-14 01:28:33 | vstinner | create | |
|