Python print unicode list

2020-03-02 03:58发布

With the following code

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

I got

[u'工', u'工']

How can I remove the leading u so that the content of msg is:

['工', '工']

1条回答
▲ chillily
2楼-- · 2020-03-02 04:41
>>> import sys
>>> lst = [u'\u5de5', u'\u5de5']
>>> msg = repr([x.encode(sys.stdout.encoding) for x in lst]).decode('string-escape')
>>> print msg
['工', '工']
查看更多
登录 后发表回答