Checking a Character Is Fullwidth or Halfwidth in Python
You can check the width of the character using unicodedata.east_asian_width(unichr)
:
1 | import unicodedata |
It has the following returned values:
1 | # East_Asian_Width (ea) |
Returned values of 'W'
, 'F'
and 'A'
should be considered as full-width on Windows.
Reference: http://www.unicode.org/reports/tr44/tr44-4.html#Validation_of_Enumerated
On POSIX platform, the quote characters (u'“'
and u'”'
) are considered as ambiguous, which are actually 1 character width in console. For console usage, you may try a 3rd-party library urwid
:
1 | from urwid.util import str_util |