Using a ~/.pdbrc file to customize the Python Debugger
Did you know that you can customize the Python debugger (PDB) by creating custom aliases within a .pdbrc file in your home directory or Python’s current working directory? I recently learned ...
Source: treyhunner.com
Did you know that you can customize the Python debugger (PDB) by creating custom aliases within a .pdbrc file in your home directory or Python’s current working directory? I recently learned this and I’d like to share a few helpful aliases that I now have access to in my PDB sessions thanks to my new ~/.pdbrc file. The aliases in my ~/.pdbrc file Here’s my new ~/.pdbrc file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 # Custom PDB aliases # dir obj: print non-dunder attributes and methods alias dir print(*(f"%1.{n} = {v!r}" for n, v in __import__('inspect').getmembers(%1) if not n.startswith("__")), sep="\n") # attrs obj: print non-dunder data attributes alias attrs import inspect as __i ;; print(*(f"%1.{n} = {v!r}" for n, v in __i.getmembers(%1, lambda v: not __i.isroutine(v)) if not n.startswith("__")), sep="\n") ;; del __i # vars obj: print instance variables (object must have __dict__) alias vars print(*(f"%1.{k} = {v!r}" for k, v in vars(%1).items()), sep="\n") # src