The dictionary type outputs properly even in Japanese. I'm very grateful. It also supports dictionary types with complicated structures.
For example, use it as follows.
dic={} #Make the contents appropriately
pp(dic) #Just output
a=pp_str(dic) #When receiving the result in a variable
Get it from github below. With windows, easy_install didn't work. (There was no error ... Did you forget something?)
Two files in the prettyprint folder https://github.com/taichino/prettyprint/tree/master/prettyprint It works if you arrange it properly.
I confirmed the operation on ubuntu. I think it's easier than printing (pp ()). There are various pps and I'm not sure about it ...
** When using with python3 ** Convert the print statement to parentheses and It worked if the return value of the pp_str () function below eval was simply set to orig.
However, when the u code was included, the characters were garbled this time> <
Postscript:
return orig.encode('utf-8').decode('unicode_escape') And the Japanese display has passed! Reference: In this example, the encoding / decoding is reversed. http://kwatch.houkagoteatime.net/blog/2013/12/07/python-tips/
By examination, python3 already had a pprint module. Import it into the original pretyprint.py and change the original pp function to pp_ etc. W that works for the time being with the following description
However, the type of the return value of this one is a unique class I don't know if the contents can be taken out without checking
import pprint
def pp(obj):
pprint.pprint(obj)
reference I want to pretty print a list and dictionary including Japanese in Python http://taichino.com/programming/1599
taichino/prettyprint https://github.com/taichino/prettyprint
Recommended Posts