2

エンコードしようとしましたが、成功しませんでした。

text = "don\\u2019t think"
textencode = text.encode('utf-8').split(" ")
print textencode

結果はまだ ['don\u2019t', 'think']

私は[「しない」、「考える」]を得ようとしました

なにか提案を?

4

2 に答える 2

3

Python2を使用しているようです。これはあなたが探しているものですか?

>>> text = u"don\u2019t think"
>>> textencode = text.encode('utf-8').split(" ")
>>> print textencode[0]
don’t

Python3 は Unicode オブジェクトをよりうまく処理します

>>> text = "don\u2019t think"
>>> textencode = text.split(" ")
>>> textencode
['don’t', 'think']
于 2013-03-07T15:32:46.940 に答える
-1

Python2.xでは

>>> text = u"don\u2019t think"
>>> textencode = text.encode('utf-8').split(" ")
>>> print textencode
['don\xe2\x80\x99t', 'think']
>>> print textencode[0]
don’t

二重引用符の前に接頭辞「u」を付けます。

于 2013-03-07T15:37:34.257 に答える