I can pretty print JSON from the command line easily:
$ echo '{"hello": "world"}' |python -mjson.tool
{
"hello": "world"
}
However it doesn't work for Python dictionaries (obviously):
$ echo "{'hello': None}" |python -mjson.tool
Expecting property name: line 1 column 1 (char 1)
Is there some built-in class I can use similar to json.tool
to pretty print Python data structures?
This project is a nice solution to this problem:
https://github.com/wolever/pprintpp
From the README:
$ pip install pprintpp
$ echo "{'hello': 'world'}" | pypprint
{'hello': 'world'}