Printing dicts (and objects) legibly: keys aligned, arrays summarized,
nested reprs indented. Plus attribute (dot) access.
aligned: render key-value pairs with the keys aligned, summarizing arrays and indenting nestedreprs to their key.AlignedDict: a dict printed byaligned.DotDict: the same, plus attribute (dot) style access.AlignedRepr: provides__repr__(for subclassing) viaaligned.get0: the first value of a dict.
- Put DotDict and AlignedDict each in their own module
The printing was replaced by the (much smaller) repr written for
MiniRes, which now shares it.
Consequently:
- The package is now only about printing dicts (plus dot access): the
dict/list utilities --
intersect,complement,prodct,transpsand thetranspose_*family,deep_getattr,deep_hasattr,flexcomp-- are gone. They originated in, and are already vendored by, DAPPER (dapper/tools/struct.py). 595 -> 190 lines. alignedandAlignedReprare new;NicePrintis an alias of the latter.printoptsis gone barindent;MIN_LINEWIDTHtoo.- Keys are no longer quoted,
__str__is no longer distinct from__repr__, and the line width is fixed (70) rather than the terminal's, so that output is reproducible. - Recursion is guarded by the stdlib's
reprlib.recursive_repr(...), rather than by hand. - numpy stays an optional, lazy dependency: arrays are summarized if it is already imported, and it is never imported on its account.
See alternatives:
- https://github.com/mewwts/addict
- https://github.com/ducdetronquito/scalpl
- https://github.com/srevenant/dictlib
- https://pypi.org/project/dict/
- https://pypi.org/project/dicty/
- https://pypi.org/project/print-dict/
- https://pypi.org/project/dictionaries/
- https://github.com/wolever/pprintpp
Answer SO.com questions: https://www.google.com/search?q=python+aligned+dict&oq=python+aligned+dict