Message145497
| Author |
vstinner |
| Recipients |
Nicholas.Cole, ezio.melotti, inigoserna, loewis, tchrist, vstinner, zeha |
| Date |
2011年10月14日.01:28:32 |
| SpamBayes Score |
1.006209e-10 |
| Marked as misclassified |
No |
| Message-id |
<1318555715.45.0.571457855494.issue12568@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
> 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. |
|