In Python 2.x, you can use the unicode.translate
method to translate one Unicode code to 0, 1 or more code points using
replacement_string = original_string.translate(table)
The following code sets up a translation table that will display the full width equivalents of all ASCII graphic characters for their ASCII equivalents:
# ! is 0x21 (ASCII) 0xFF01 (full); ~ is 0x7E (ASCII) 0xFF5E (full) table = dict((x + 0xFF00 - 0x20, unichr(x)) for x in xrange(0x21, 0x7F))
(link: see Wikipedia )
If you want to handle the spaces the same way do table[0x3000] = u' '
source share