Community Python Snippet

The 30-Line Debug Print I Keep in My Dotfiles

A pretty-printer for Python objects that I paste into every new project. Shows types, depth, and truncates long containers, so I stop reaching for `pprint` mid-incident.

The 30-Line Debug Print I Keep in My Dotfiles

A pretty-printer for Python objects that I paste into every new project. Shows types, depth, and truncates long containers, so I stop reaching for `pprint` mid-incident.

Python
Compiler
3 snippets
debugging
py-decorators
utility
code-template
owentoure

By @owentoure

February 14, 2026

·

Updated May 18, 2026

994 views

4

4.5 (13)

This is the debug-print I have been pasting into Python projects since around 2019. It prints to stderr so it never mixes with structured stdout, recurses one level at a time with two-space indentation, and bails out on cycles via an id() set. The two constants at the top, _MAX_ITEMS and _MAX_STR, are the part that matters most during real incidents: when a payload is 50k items deep, pprint will lock your terminal, but dprint shows the first five and a trailing count. I leave the file at ~/.local/lib/python/dprint.py and import sys; sys.path.insert(0, ...) it from a breakpoint() shell.