[IPython-user] debugging in ipython
Wed Oct 22 20:51:43 CDT 2008
Note, I have resolved these questions through other channels and
thought a follow-up post might be appropriate.
On Oct 18, 2008, at 9:41 AM, Tom K. wrote:
> I had a question about debugging in ipython [sorry if this is a
> "FAQ" - if there is a way to search the archives, please let me know]:
First of all, the IPython - User forum is searchable at nabble,
here's a link:
> When I use "pdb" I lose some of the key ipython features; tab
> completion and syntax coloration are the ones I miss the most. Is
> there another debug module besides pdb, or a way to configure / run
> the debugger within ipython, in order to get these features
> functional at the pdb prompt?
> I am using 0.8.4 under Python 2.4.2 but looking at the release
> notes on the subsequent versions of IPython the other night I did
> not see anything about debugging mentioned there. I enter the
> debugger as follows:
> >>> import pdb
> >>> objectInstance = ... create an object ...
> >>> pdb.run('objectInstance.method()', globals(), locals())
My post prompted this response from a close colleague who works down
the hall from me:
I think IPython already supports some degree of tab completion and
syntax coloration while debugging in both 0.8.4 and 0.9.1.
One way to so this is to do
In : %run -d myscript.py
ipdb> b somefile.py:linenumber
and it stops at the breakpoint you set. At this point a syntax
colored source listing is printed and I'm able to use tab completion
to print variables
ipdb> p some[TAB] gets expanded to
ipdb> p somevariable
I've tried this and it works great! This technique does not require
you to touch any code (e.g. inserting pdb.set_trace() or raise an
exception) to set a breakpoint at an arbitrary point. Also, the -i
option to %run allows my script to work with existing variables in
the IPython namespace.
More information about the IPython-user