I\'m running my Python program and have a point where it would be useful to jump in and see what\'s going on, and then step out again. Sort of like a temporary console mode.
I use pdb for this purpose. I realize Emil already mentioned this in his answer, but he did not include an example or elaborate on why it answers your question.
for thing in set_of_things:
import pdb; pdb.set_trace()
do_stuff_to(thing)
You can read and set variables by starting your command with an exclamation point. You can also move up and down the stack (commands u
and d
), which InteractiveConsole
does not have built-in mechanisms to do.
To have the program continue executing, use the c
command. In the above example it will enter the debugger every loop iteration, so you might want to wrap the set_trace()
call in an if
sentence.