[Numpy-discussion] Are there command similar as Matlab find command?

Anne Archibald peridot.faceted@gmail....
Tue Sep 30 00:25:32 CDT 2008

2008/9/30 frank wang <f.yw@hotmail.com>:

> I really do not know the difference of debug mode and the pdb debugger. To
> me, it seems that pdb is only way to debug the python code. How do the
> expert of numpy/python debug their code? Are there any more efficient way to
> debug the code in python world? I used to use matlab which comes with a nice
> debugger. But now I really want to try the open source software and I found
> python/numpy is a nice tool. The only lagging piece of python/numpy
> comparing with matlab is the powerful debuggign capability.

I think you will find that the debugger, pdb, is a good analog to
matlab's debugging mode. The way I usually debug a piece of code looks
something like:

[in window A] edit foomodule.py to add a function frobnicate()
[in window B, which has a running ipython session]
>>> import foomodule
>>> reload(foomodule)
>>> frobnicate()
<some exception happens>
>>> %pdb
>>> frobnicate()
<exception happens again>
(pdb) print some_variable
[in window A] <wait a minute, some_variable should be 13 at this
point...> edit foomodule.py to fix the bug
[in window B]
>>> reload(foomodule)
>>> frobnicate()

Alternatively, I write a test_foomodule.py, which contains a suite of
unit tests. I run these tests and get dropped into a debugger when one
fails, and I try to track it down.

The main problem you ran into is that the debugger is not just any old
python prompt. It has its own commands. It also, confusingly, will
accept python commands, as long as they don't conflict with an
internal command. I got into the habit of, when I wanted to run some
python thing, writing
(pdb) p 17+13
rather than just
(pdb) 17+13
If you had simply written
(pdb) p where(a>13)
everything would have been fine.


More information about the Numpy-discussion mailing list