Hello. I found here how to make non-ascii characters in the list look good: "How to print tuples of unicode strings in original language (not u'foo' form)" / questions / 621321 / how-to-print-tuples-of-unicode-strings-in-original-language-not-ufoo-form).
s = [1, 'Day', ['Book']]
print(list_str(s)) # ==> [1, 'Day', ['Book']]
print(s) # ==> [1, '\xe6\x97\xa5', ['\xe6\x9c\xac']]
def list_str(x):
if not isinstance(x, list):
if isinstance(x, str):
return '\'%s\'' % x
return str(x)
items = ', '.join([list_str(x) for x in x])
return '[%s]' % items
Besides, The method of https://pypi.python.org/pypi/prettyprint is
import json
def list_str(x):
return eval("u'''%s'''" % json.dumps(x)).encode('utf-8')
s = [1, 'Day', ['Book']]
print(list_str(s)) # => [1, "Day", ["Book"]]
Recommended Posts