gaggina
gaggina

Reputation: 5425

How to decode this string (it's hex?)?

I'm trying to understand how encoding/decoding string works in Python, but I'm getting pretty confused.

If I've got a string like this:

'\x87\x0e)\xb9\xb0\x0f\t"c\xc7\xf1\x97B\xc6\x17\xee\xab\x1d\xbf\xc0\xd0\x06j\xc3'

Which type is this? Hex? And how to convert it to utf-8?

Upvotes: 0

Views: 774

Answers (1)

Yevgen Yampolskiy
Yevgen Yampolskiy

Reputation: 7198

This way you can construct Unicode object out of this string

u='\x87\x0e)\xb9\xb0\x0f\t"c\xc7\xf1\x97B\xc6\x17\xee\xab\x1d\xbf\xc0\xd0\x06j\xc3'.decode('UTF16')
print type(u)

Upvotes: 1

Related Questions