spacepy.toolbox.dictree

spacepy.toolbox.dictree(in_dict, verbose=False, spaces=None, levels=True, attrs=False, print_out=True, **kwargs)[source]

pretty print a dictionary tree

Parameters:
in_dictdict

a complex dictionary (with substructures)

verbosebool, default False

print more info

spacesstr (optional)

string will added for every line

levelsint (optional)

number of levels to recurse through (True, the default, means all)

attrsbool, default False

display information for attributes

print_outbool, default True

New in version 0.5.0.

Print output (original behavior); if False, return the output.

Raises:
TypeError

Input does not have keys or attrs, cannot build tree.

Examples

>>> import spacepy.toolbox as tb
>>> d = {'grade':{'level1':[4,5,6], 'level2':[2,3,4]}, 'name':['Mary', 'John', 'Chris']}
>>> tb.dictree(d)
+
|____grade
     |____level1
     |____level2
|____name

More complicated example using a datamodel:

>>> from spacepy import datamodel
>>> counts = datamodel.dmarray([2,4,6], attrs={'units': 'cts/s'})
>>> data = {'counts': counts, 'PI': 'Dr Zog'}
>>> tb.dictree(data)
+
|____PI
|____counts
>>> tb.dictree(data, attrs=True, verbose=True)
+
|____PI (str [6])
|____counts (spacepy.datamodel.dmarray (3,))
    :|____units (str [5])

Attributes of, e.g., a CDF or a datamodel type object (obj.attrs) are denoted by a colon.