Alex Rivera | Logout

Convert unicode codepoint to UTF8 hex in python

Asked 2009-05-15T10:13:24.533
16

I want to convert a number of unicode codepoints read from a file to their UTF8 encoding.

e.g I want to convert the string 'FD9B' to the string 'EFB69B'.

I can do this manually using string literals like this:

u'\uFD9B'.encode('utf-8')

but I cannot work out how to do it programatically.

Edit
Report

1 Answer

3
data_from_file='\uFD9B'
unicode(data_from_file,"unicode_escape").encode("utf8")
answered 2009-05-15T15:05:03.163

Your Answer