May 28

Everybody knows “import pdb; pdb.set_trace()”, that’s probably the first thing anyone would do when you’re trying to hunt for a bug or hit an exception (“pdb.pm()” ?). Its just as easy to embed IPython or a plain old Python shell in a python script.

from IPython.Shell import IPShellEmbed
ishell = IPShellEmbed()
ishell()

The IPython manual covers this in detail.
Another way would be to subclass code.InteractiveConsole as mentioned in this Python Cookbook entry.