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).
>>> data = [1./3, 1./49*49, 84.6/423]
>>> data
[0.3333333333333333, 0.9999999999999999, 0.19999999999999998]
>>> import pprint
>>> pprint.pprint(data)
[0.3333333333333333, 0.9999999999999999, 0.19999999999999998]
>>> import scitools.pprint2 as pprint2
>>> pprint2.pprint(data)
[0.333333, 1, 0.2]
>>> pprint2.float_format = '%.12E'
>>> pprint2.pprint(data)
[3.333333333333E-01, 1.000000000000E+00, 2.000000000000E-01]
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.
Pretty-print a Python object to a stream [default is sys.stdout].
Format a Python object into a pretty-printed representation.
Determine if object requires a recursive representation.
Version of repr() which can handle recursive data structures.
Methods
format(object, context, maxlevels, level) | Format object for a specific context, returning a string |
isreadable(object) | |
isrecursive(object) | |
pformat(object) | |
pprint(object) |
Handle pretty printing operations onto a stream using a set of configured parameters.