Pretty print python objects in a tree format.
Project description
printree
Tree-like formatting for arbitrary python data structures.
Similar to pretty print (pprint) but in the form of a tree:
>>> from printree import ptree, ftree
>>> ptree({"x", len, 42}) # will print to the output console
`- . [items=3]
|- 0: <built-in function len>
|- 1: 42
`- 2: x
>>> ftree({"x", len, 42}) # will return a string representation
'`- . [items=3]\n |- 0: <built-in function len>\n |- 1: 42\n `- 2: x'
Instances of abc.Iterable (with the exception of str & bytes) should be translated into a tree-like form. All other objects will be considered "leaf nodes":
>>> dct = {
... "foo": [],
... True: {
... "uno": {"ABC", "XYZ"},
... "dos": r"B:\newline\tab\like.ext",
... "tres": {
... "leaf": b"bytes",
... "numbers": (42, -17, 0.01)
... },
... },
... ("unsortable", ("tuple", "as", "key")):
... {"multi\nlined\n\ttabbed key": "multi\nline\n\ttabbed value"}
... }
>>> dct["recursion"] = [1, dct, 2]
>>> ptree(dct)
`- . [items=4]
|- foo [empty]
|- True [items=3]
| |- dos: B:\newline\tab\like.ext
| |- tres [items=2]
| | |- leaf: b'bytes'
| | `- numbers [items=3]
| | |- 0: -17
| | |- 1: 0.01
| | `- 2: 42
| `- uno [items=2]
| |- 0: ABC
| `- 1: XYZ
|- ('unsortable', ('tuple', 'as', 'key')) [items=1]
| `- multi
| lined
| tabbed key: multi
| line
| tabbed value
`- recursion [items=3]
|- 0: 1
|- 1: <Recursion on dict with id=2317960566912>
`- 2: 2
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
printree-0.1.1.tar.gz
(4.9 kB
view hashes)