如何改变'\ x ??'在python中unicode?

时间:2013-02-07 10:43:14

标签: python encoding

我有一个字符串:

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

想要使用python

将其更改为unicode

我该怎么做?

1 个答案:

答案 0 :(得分:6)

已经是 UTF-8数据; python向您显示字符串文字形式。

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

以上行将UTF-8数据解码为具有unicode打印.decode('utf8') and prints that; the unicode`对象的statement inspects the encoding used by my terminal and re-encodes the对象,以便我的终端可以正确显示它。

您可能想要阅读Python和Unicode: