[IPython-user] debugging a function w/ipython
belinda thom
bthom at cs.hmc.edu
Fri Jan 5 01:56:41 CST 2007
Fernando,
I am continuing this thread from a one-on-one email so the answers
can be available on the list.
> 2) The lack of run on a particular portion of a file really hampers
> debugging in that you can't (as opposed to IDLE) do something as
> simple as clicking on a line of code to set a breakpoint on a line.
> (I'm used to the matlab debugger, with its xemacs interface).
>
> F Perez said:
>As we said, you can't set a function-named breakpoint, but you /can/
>set a line-number breakpoint:
>
>run -d -b25 foo
>
>will run foo.py with a breakpoint pre-set at line #25. Were you aware
>of that, or does it not fit your needs?
Perhaps what I am desiring isn't even possible; Python's mindset is
sufficiently different from the normal mode I'm used to (C++, Matlab)
that I'm still approaching some problems from the wrong viewpoint,
making tasks harder than they otherwise would be.
What I am currently not thrilled about w/the way I develop code in
ipython is that I find I often have to modify the code itself to
debug in a location I'm interested in.
Suppose I had a module foo.py:
class blah:
<some class def'n stuff, including a method called bar>
<perhaps some other classes or functions...>
<the if __name__ == "__main__" check>:
b = blah(...)
b.foo(...)
When I wish to debug foo, this works fine, but then I want to debug
other things, so I have to keep adding code I'd like to execute to
the bottom of a file. What I'd much rather prefer is to be able to
execute commands at the ipython command-line and have them just stop
in the debugger at a particular line-number that I specify. Ideally,
this would be "mouse-clickable" but I think the emacs/ipython code is
not currently being actively developed (perhaps I'll get around to an
extension like this someday; I dunno; I'm a big fan of emacs and use
it for just about everything). But short of mouse-clickable, I'd like
to be able to set a breakpoint in foo.py w/o having to add code at
the bottom of the file to get it to break where I am asking it to
when I use run.
Am I missing something really basic? Or does this type of debugging
scheme (which I used heavily in Matlab) not make sense when
developing Python code (and if so, why?)?
Again, thanks for your thoughtful and well-considered answers. One
great thing about python-related lists is that so many people are
excited about it that it is easy to jumpstart learning online.
I also have a namespace question, but will follow that up in another
email.
--b
More information about the IPython-user
mailing list