Converting from hexadecimal string to unicode
How can I convert a string 'dead'
to a unicode string u'\xde\xad'
?
Doing this action:
from binascii import unhexlify
out = ''.join(x for x in [unhexlify('de'), unhexlify('ad')])
creates a string <type 'str'>
'\xde\xad'
Trying to use Unicode.join () like this:
from binascii import unhexlify
out = ''.join(x for x in [u'', unhexlify('de'), unhexlify('ad')])
results in an error:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xde in position 0: ordinal not in range(128)
+2
user188956
source
to share
2 answers
See this way of using Python unicode and use something similar to:
unicode('\x80abc', errors='replace')
or
unicode('\x80abc', errors='ignore')
+1
source to share