Python 打印 unicode 列表

标签 python string python-2.7 python-unicode

用下面的代码

lst = [u'\u5de5', u'\u5de5']
msg = repr(lst).decode('unicode-escape')
print msg

我得到了

[u'工', u'工']

如何删除前导 u 以便 msg 的内容为:

['工', '工']

最佳答案

>>> import sys
>>> lst = [u'\u5de5', u'\u5de5']
>>> msg = repr([x.encode(sys.stdout.encoding) for x in lst]).decode('string-escape')
>>> print msg
['工', '工']

关于Python 打印 unicode 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22745876/

相关文章:

php - [Linux, Ubuntu] : Executing a Python script with different users results in different behaviours

python - 如何从 url 中删除查询字符串?

regex - Perl:用它们的计数替换连续的数字

字符串连接的 C++ 开销

java - 当字符串在 Java 8 中没有分隔符时,根据提供的键从字符串创建映射

python - macOS Sierra 上的 nltk

python - 将前几行详细信息存储在 Dataframe 的字典列表中

python - "group by"或 "uniq"的统计信息

python - 值错误 : invalid literal for long() with base 10: '5B'

python - django:管理站点未格式化