Python print unicode list
10,561
>>> import sys
>>> lst = [u'\u5de5', u'\u5de5']
>>> msg = repr([x.encode(sys.stdout.encoding) for x in lst]).decode('string-escape')
>>> print msg
['工', '工']
Comments
-
gongzhitaao almost 2 years
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 ofmsg
is:['工', '工']
-
gongzhitaao about 10 yearsI've got a one more question related to this. Pleas see my updated post.
-
falsetru about 10 years@gongzhitaao, Where is the
one more question
? -
falsetru about 10 years@gongzhitaao,
more_msg = ...
just works. What is the problem? -
gongzhitaao about 10 yearsNo, it doesn't,
'ascii' codec can't decode byte
is the error message.