stop exeuction and give my a prompt

Peter Hansen peter at engcorp.com
Tue Apr 1 21:44:00 EST 2003


Syver Enstad wrote:
> 
> David Bear <david.bear at asu.edu> writes:
> 
> > I would like to have the ability to insert a statement in my code that
> > would stop program execution at that point and give me a python prompt. 

> Use the python debugger. In the most primitive way is to use it from
> the interactive prompt.
> 
> Do:
> import pdb # at the top of your sourcefile
> 
> Do:
> pdb.set_trace() # at the point you want to debug.

And note that when you do that, the context of the prompt
is *inside* set_trace(), or somewhere like that, so to see
the local context from which it was called, you have to execute
a "return" or "r" command.  

Also be careful of trying to work with one-character variable
names, as the debugger tends to use many of these as shortcuts
for various commands.  

And there are probably other gotchas, but it's pretty damn
convenient if you ask me!

-Peter




More information about the Python-list mailing list