a blog by Marius Gedminas

Posts tagged Python

Object graphs with graphviz

This is a continuation of Python object graphs. import gc import inspect import types import weakref import os I've already mentioned gc and inspect. types and weakref help me distinguish certain kinds of objects. os is needed to spawn dot to generate an image from the textual graph description. def show_backrefs(objs, max_depth=3, extra_ignore=(), filter=None, too_many=10): This function starts from a given object (or a list of objects) and follows the reference chains backwards, up to a given maximal depth.