eran
eran

Reputation: 15136

How to change '\x??' to unicode in python?

I have a string:

\xe2\x80\x8e\xd7\x93\xd7\x9c\xd7\x99\xd7\xaa\xe2\x80\x8e

want to achange it to unicode using python

how do I do that?

Upvotes: 0

Views: 2465

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1123400

That is UTF-8 data already; python is showing you the string literal form.

>>> print '\xe2\x80\x8e\xd7\x93\xd7\x9c\xd7\x99\xd7\xaa\xe2\x80\x8e'.decode('utf8')
‎דלית‎

The above line decodes the UTF-8 data to a unicode object with .decode('utf8') and prints that; theprintstatement inspects the encoding used by my terminal and re-encodes theunicode` object so that my terminal can display it properly.

You may want to read up on Python and Unicode:

Upvotes: 6

Related Questions