pretty_print

Functions and classes for pretty printing.

New in version 0.10.0.

Classes:

FancyPrinter([indent, width, depth, stream, …])

Subclass of PrettyPrinter with different formatting.

Functions:

simple_repr(*attributes[, show_module])

Adds a simple __repr__ method to the decorated class.

class FancyPrinter(indent=1, width=80, depth=None, stream=None, *, compact=False, sort_dicts=True)[source]

Bases: PrettyPrinter

Subclass of PrettyPrinter with different formatting.

Parameters
  • indent (int) – Number of spaces to indent for each level of nesting. Default 1.

  • width (int) – Attempted maximum number of columns in the output. Default 80.

  • depth (Optional[int]) – The maximum depth to print out nested structures. Default None.

  • stream (Optional[IO[str]]) – The desired output stream. If omitted (or False), the standard output stream available at construction will be used. Default None.

  • compact (bool) – If True, several items will be combined in one line. Default False.

  • sort_dicts (bool) – If True, dict keys are sorted. Only takes effect on Python 3.8 and later, or if pprint36 is installed. Default True.

simple_repr(*attributes, show_module=False, **kwargs)[source]

Adds a simple __repr__ method to the decorated class.

Parameters
  • attributes – The attributes to include in the __repr__.

  • show_module (bool) – Whether to show the name of the module in the __repr__. Default False.

  • **kwargs – Keyword arguments passed on to pprint.PrettyPrinter.