我试着编码,但没有成功。
text = "don\\u2019t think"
textencode = text.encode('utf-8').split(" ")
print textencode结果仍然是'don\u2019t','think‘
我试着说“不要”,“思考”
有什么建议吗?
发布于 2013-03-07 23:32:47
看起来您正在使用Python2。这就是你要找的东西吗?
>>> text = u"don\u2019t think"
>>> textencode = text.encode('utf-8').split(" ")
>>> print textencode[0]
don’tPython3可以更好地处理unicode对象。
>>> text = "don\u2019t think"
>>> textencode = text.split(" ")
>>> textencode
['don’t', 'think']发布于 2013-03-07 23:37:34
在python 2.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‘前缀。
https://stackoverflow.com/questions/15275005
复制相似问题