python - 在 Python 3 中显示 unicode 字符

标签 python list unicode

我在显示 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/

相关文章:

python - 计算图中 2 个节点之间的距离

python - 循环地将操作数列表减少为单个结果

java - 如何在 Java 中创建匹配正则表达式的字符串数组列表?

delphi - 使用 Delphi 2010,如何将 Unicode 字符串转换为十六进制字符串,然后再转换回来?

emacs - 如何在 Clojure 正则表达式中使用 unicode (UTF-8) 字符?

python - 修改pandas dataframe的日期索引

python - 在windows上安装python/sphinx环境?

python - 类型错误 : unsupported operand type(s) for +: 'Timestamp' and 'float'

python - 如何在 Python 2.7 中以字符串格式包含 %?

python - 有没有办法使用 Python 在 SQLite 中正确排序 unicode 字符串?