PDB how to define a global inspection function?

Charles Fox (Sheffield) charles.fox at gmail.com
Tue Feb 8 12:23:45 CET 2011


Hi guys, I'm new to this group and have a question about debugging.
I'm stepping through my code (using emacs pdbtrack and python-mode.el)
and would like to isnpect objects as I go.  So I've defined a little
object print function,

def p(obj):
    print obj
    print obj.__class__
    d=dir(obj)
    for a in d:
        print a, "=", getattr(obj, a)


however it only works if the function is imported by whatever module I
am currently debugging.  I'd like it to be available globally so I can
stop and inspect anything as I step through various modules (including
external libraries).  Is there a way to put it in the global scope for
pdb to use?   Also is there a way to automatically import it whenever
pdb starts up (like a matlab startup file)?     (I'm not using ipython
as it's not happy with pdbtrack in emacs, so am launching from emacs M-
x pdb command).

thanks,
Charles Fox



More information about the Python-list mailing list