Pretty Print for Python

A simple but a goodie - pretty print in Python. For those of you working with AWS everything from the API is JSON, impossible to read improperly formatted. Of course there is a solution, and of course I can never find it.

The pprint library is your friend (obviously there are other solutions, this is just the most repeatable I've found and doesn't requre doing funky things with the json module)

This is almost to the point of just being in every python script I write because it's so much easier.

import pprint
pp = pprint.PrettyPrinter(indent=4)

Then you just call pp.pprint(string) to pretty print things.

And the obligatory test

Python 3.8.5 (default, May 27 2021, 13:30:53) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pprint
>>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni']
>>> stuff.insert(0, stuff)
>>> pprint.pprint(stuff)
[<Recursion on list with id=140574604220352>,
 'spam',
 'eggs',
 'lumberjack',
 'knights',
 'ni']

Great for Jupyter!