Skip to content

Latest commit

 

History

35 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

struct-tools

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 nested reprs to their key.
  • AlignedDict: a dict printed by aligned.
  • DotDict: the same, plus attribute (dot) style access.
  • AlignedRepr: provides __repr__ (for subclassing) via aligned.
  • get0: the first value of a dict.

TODO

  • Put DotDict and AlignedDict each in their own module

Changes in 0.3.0

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, transps and the transpose_* family, deep_getattr, deep_hasattr, flexcomp -- are gone. They originated in, and are already vendored by, DAPPER (dapper/tools/struct.py). 595 -> 190 lines.
  • aligned and AlignedRepr are new; NicePrint is an alias of the latter.
  • printopts is gone bar indent; MIN_LINEWIDTH too.
  • 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:

Answer SO.com questions: https://www.google.com/search?q=python+aligned+dict&oq=python+aligned+dict

About

Tools for dicts and other data containers

Resources

Stars

1 star

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages