[PYTHON] In print, the non-ascii characters in the list look great

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

In print, the non-ascii characters in the list look great
Put together consecutive values in the list
Just print the selected object in Blender
Cut out A4 print in the image
Change the list in a for statement
Print the include header path in clang
Get the EDINET code list in Python
[Python] Sort the list of pathlib.Path in natural sort
Check if the characters are similar in Python
Make a copy of the list in Python
Get only the subclass elements in a list
I can't enter characters in the text area! ?? !! ?? !! !! ??
Search by the value of the instance in the list
How to identify the element with the smallest number of characters in a Python list?
Extract and list personal names and place names in the text
[python] Get the list of classes defined in the module
Read the linked list in csv format with graph-tool
Shift the alphabet string by N characters in Python
[Python] Outputs all combinations of elements in the list
[Python] How to output the list values in order