scitools.pprint2

Support to pretty-print lists, tuples, & dictionaries recursively.

Very simple, but useful, especially in debugging data structures. Slight extension of the original pprint module in Python such that floating-point numbers can be written with a specificed format (float_format) and not by their repr string (which explicitly displays round-off errors).

Classes:

  • PrettyPrinter(): Handle pretty-printing operations onto a stream using a configured set of formatting parameters.

Functions:

  • pformat(): Format a Python object into a pretty-printed representation.
  • pprint(): Pretty-print a Python object to a stream [default is sys.stdout].
  • saferepr(): Generate a ‘standard’ repr()-like value, but protect against recursive data structures.

Global data:

  • float_format: String containing the printf format for formatting float objects.
scitools.pprint2.pprint(object, stream=None, indent=1, width=80, depth=None)[source]

Pretty-print a Python object to a stream [default is sys.stdout].

scitools.pprint2.pformat(object, indent=1, width=80, depth=None)[source]

Format a Python object into a pretty-printed representation.

scitools.pprint2.isreadable(object)[source]

Determine if saferepr(object) is readable by eval().

scitools.pprint2.isrecursive(object)[source]

Determine if object requires a recursive representation.

scitools.pprint2.saferepr(object)[source]

Version of repr() which can handle recursive data structures.

class scitools.pprint2.PrettyPrinter(indent=1, width=80, depth=None, stream=None)[source]

Methods

format(object, context, maxlevels, level) Format object for a specific context, returning a string
isreadable(object)
isrecursive(object)
pformat(object)
pprint(object)
format(object, context, maxlevels, level)[source]

Format object for a specific context, returning a string and flags indicating whether the representation is ‘readable’ and whether the object represents a recursive construct.

isreadable(object)[source]
isrecursive(object)[source]
pformat(object)[source]
pprint(object)[source]

This Page