2013-02-07 31 views
0

我有一個字符串:如何更改' x ??'在python unicode?

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

想achange它使用python

我怎麼做,要統一?

+0

的Python 2或Python 3?如果Python 3,它真的是一個字符串還是一個「字節」對象? –

+0

python 2.7是我的版本 – eran

回答

6

UTF-8數據已經; python向你展示了字符串文字形式。

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

上述符合.decode('utf8') and prints that; the打印statement inspects the encoding used by my terminal and re-encodes the unicode`對象的UTF-8的數據至一個unicode對象進行解碼,使我的終端能夠適當地顯示它。

您可能需要Python和Unicode的讀了起來:

+0

謝謝。如果我想在unicode中使用它? – eran

+0

我的代碼示例中的'.decode('utf8')'調用確實*它會打印Unicode(使用python'print'語句將其自動轉換爲我的終端編碼)。 –