STINNER Victor <victor.stin...@haypocalc.com> added the comment:

> 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.

----------
keywords: +patch
Added file: http://bugs.python.org/file23401/locale_width.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue12568>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to