Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python print unicode list

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:

['工', '工']
like image 625
gongzhitaao Avatar asked Mar 30 '14 15:03

gongzhitaao


1 Answers

>>> import sys
>>> lst = [u'\u5de5', u'\u5de5']
>>> msg = repr([x.encode(sys.stdout.encoding) for x in lst]).decode('string-escape')
>>> print msg
['工', '工']
like image 75
falsetru Avatar answered Oct 15 '22 15:10

falsetru