[英]Displaying unicode characters in Python 3
I have issues with displaying Unicode characters. 我在显示Unicode字符时遇到问题。 As an output I have this list (only on online IDEs):
作为输出,我有此列表(仅在在线IDE上):
[u'\u0413', u'\0434', u'\043b']
How can I convert this sequence to normally visible text? 如何将该序列转换为通常可见的文本? I have
# -*- coding: utf-8 -*-
in header and also each string marked as Unicode like u'String' 我在标题中有
# -*- coding: utf-8 -*-
,而且每个字符串都标记为Unicode,如u'String'
I tried to use code: myList = repr([x.encode(sys.stdout.encoding) for x in lst]).decode('string-escape')
but it's not working and output still the same. 我尝试使用代码:
myList = repr([x.encode(sys.stdout.encoding) for x in lst]).decode('string-escape')
但是它不起作用,输出仍然相同。
In Python 3, this will work directly: 在Python 3中,这将直接起作用:
>>> [u'\u0413', u'\0434', u'\043b']
['Г', '#4', '#b']
In Python 2, you can use the print statement to print individual values: 在Python 2中,可以使用print语句打印单个值:
>>> for val in [u'\u0413', u'\0434', u'\043b']:
... print val
...
Г
#4
#b
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.