我在显示 Unicode 字符时遇到问题。 作为输出,我有以下列表(仅在在线 IDE 上):
[u'\u0413', u'\0434', u'\043b']
如何将此序列转换为正常可见的文本?
我有
# -*- 编码:utf-8 -*-
在标题中,每个字符串都标记为 Unicode,如 u'String'
我尝试使用代码:
myList = repr([x.encode(sys.stdout.encoding) for x in lst]).decode('string-escape')
但它不起作用,输出仍然相同。
最佳答案
在 Python 3 中,这将直接起作用:
>>> [u'\u0413', u'\0434', u'\043b']
['Г', '#4', '#b']
在 Python 2 中,您可以使用 print 语句来打印各个值:
>>> for val in [u'\u0413', u'\0434', u'\043b']:
... print val
...
Г
#4
#b
关于python - 在 Python 3 中显示 unicode 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30737913/