This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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.
History
Date User Action Args
2011-10-14 01:28:35vstinnersetrecipients: + vstinner, loewis, ezio.melotti, inigoserna, zeha, Nicholas.Cole, tchrist
2011-10-14 01:28:35vstinnersetmessageid: <1318555715.45.0.571457855494.issue12568@psf.upfronthosting.co.za>
2011-10-14 01:28:34vstinnerlinkissue12568 messages
2011-10-14 01:28:33vstinnercreate