Reputation: 63
i know this type is asked alot but no answer was able to specifically help me with my problemsetup.
i have a list of ONLY Unicode codepoints so in this form: 304E 304F ...
No U+XXXX no '\XXXX' version.
Now i've tried to use stringmanipulation to recreate such strings so i can simply print the corresponding unichar. what i tried:
x = u'\\u' + listString
x = '\\u' + listString
x = '\u' + listString
the first 2 when printed just give me a '\uXXXX' string, but no idea how to make it print the char not that string.
the last one gives me this error: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-1: truncated \uXXXX escape
probably just something i dont get about unicode and stringmanipulation but i hope someone can help me out here.
Thanks in advance o/
Upvotes: 1
Views: 96
Reputation: 17960
You can use chr
to get the character for a unicode code point:
>>> chr(0x304E)
'ぎ'
You can use int
to convert a hexadecimal string to an integer:
>>> int('304E', 16)
12366
>>> chr(int('304E', 16))
'ぎ'
Upvotes: 3