[英]Python chinese characters
I have the following encoding in python 2.7:我在 python 2.7 中有以下编码:
["\xe5\x81\x9a\xe6\x88\x8f\xe4\xb9\x8b\xe8\xaf\xb4"]
I need to get the following (chinese characters) from that:我需要从中获得以下(汉字):
["做戏之说"]
Anyone knows how to decode the above to get that?任何人都知道如何解码上述内容以获得它?
You need to decode your string:你需要解码你的字符串:
>>> l = ["\xe5\x81\x9a\xe6\x88\x8f\xe4\xb9\x8b\xe8\xaf\xb4"]
>>> a = [l[0].decode('utf8')]
>>> print a[0]
做戏之说
If you want to show your Unicode inside the list you need to convert the standard representation of the list to unicode then print it:如果您想在列表中显示您的 Unicode,您需要将列表的标准表示形式转换为 unicode,然后打印它:
>>> print unicode(repr([l[0].decode('utf8')]), 'unicode-escape')
[u'做戏之说']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.