PDB how to define a global inspection function?

  • Thread starter Charles Fox (Sheffield)
  • Start date
C

Charles Fox (Sheffield)

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
 
P

Peter Otten

Charles said:
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).

For debugging purposes its OK to your function into the __builtin__
namespace:

Try it out:
.... f.write("p()\n")
....42
 
P

Peter Otten

Charles said:
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).

For debugging purposes it's OK to put your function into the __builtin__
namespace:

Try it out:
.... f.write("p()\n")
....42
 
C

Charles Fox (Sheffield)

For debugging purposes it's OK to put your function into the __builtin__
namespace:




Try it out:


...     f.write("p()\n")
...>>> import tmp

42


Thanks very much for your help, Peter, that's exactly what I was
after :)
Charles
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top