i wrote a nifty utility function which basically takes a container object (list, dictionary, or tuple), and strips all the actual content out of it, replacing all the values with None
def iscontainer(obj):
return isinstance(obj, list) or isinstance(obj, dict) or isinstance(obj, tuple)
def strip_container(container):
assert iscontainer(container), 'not a container'
if isinstance(container, list) or isinstance(container, tuple):
return [(strip_container(obj) if iscontainer(obj) else None)
for obj in container]
else:
return {k: (strip_container(v) if iscontainer(v) else None)
for (k,v) in container.items()}
so if you have dictionaries and lists and nested dictionaries and lists containing a bunch of big strings and numbers and class instances, this replaces all those bottom level entries with None values, which makes it really easy to read the "outline" of a complicated "data structure"
for example, here's what it looks like when i apply it to some code i'm debugging:
{'gt': {'depths': None,
'masks': None,
'pose': None,
'view': None,
'views': None},
'pred': {'flow': {'pred_flow': None, 'pred_view': None},
'par': {'preds': {'depth': None,
'dx': None,
'dy': None,
'mask': None,
'view': None},
'reproj': {'body': {'depth': None,
'mask': None,
'view': None},
'view': {'depth': None,
'mask': None,
'view': None}}}}}
if i hadn't used this function, all of those None values would've printed with huge numpy arrays which would've made it impossible to read