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 |
Get Python in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.