The pprint Module
The pprint module pretty-prints complicated data structures, with formatting that may be more readable than that supplied by built-in function repr (covered in repr in Built-in Functions). To fine-tune the formatting, you can instantiate the PrettyPrinter class supplied by module pprint and apply detailed control, helped by auxiliary functions also supplied by module pprint. Most of the time, however, one of the two main functions exposed by module pprint suffices.
pformat |
Returns a string representing the pretty-printing of |
pprint |
Outputs the pretty-printing of The following statements are the same: print pprint.pformat(x) pprint.pprint(x) Either of these constructs will be roughly the same as |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access