[IPython-dev] Step-by-step debugging with IPython

Darlan Cavalcante Moreira darcamo at gmail.com
Fri Jul 18 15:06:33 EDT 2014


takowl at gmail.com writes:

> On 15 July 2014 06:02, Josh Wasserstein <ribonucleico at gmail.com> wrote:
>
>> This makes me wonder if:
>>
>> 1) I am doing things wrong
>> 2) The current status of IPython does not provide the debugging
>> functionality stated in the OP.
>>
>> And the reason behind 2) could be:
>> a. Limitations of Python / execution model that make this inviable
>> b. There is not enough interest to justify an effort to improve the
>> debugging model / the relatively high complexity required to have Python /
>> IPython support this workflow
>>
>
> There's a distinct possibility that the answer is 2c: The effort is
> justified, but no-one has done it yet.
>
> I know several of us on the core team routinely just scatter print
> statements around the code when we want to debug something. Even using a
> post-mortem debugger to go up and down the stack, with no way to step
> through code, seems advanced to me.
>
> My personal take on it is that the effort necessary to learn and use a
> command-line debugger isn't really worth it for writing Python code, where
> uncaught errors automatically give you quite a bit of detail on what went
> wrong. I suspect that a good graphical debugger could be useful (I've used
> the JS debugger in Firefox, for instance).
>
> Thomas
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev


Debugging in python was annoying to me until I discovered pudb.
https://pypi.python.org/pypi/pudb

Install it through pip and then add the line below at some point in your
program
    import pudb; pudb.set_trace()
and run it as usual.

Or you don't add anything and run you program with
pudb my_program.py


The advantages of pudb when compared with standard pdb or ipdb is that
it is graphical and much easier to work with. You can step throgh code
with the 'n' key, step inside a function with the 's' key, go up or down
in the stack with 'd' and 'u', etc.

But the killer feature is the integration with IPython. At any point you
can press '!' to go to an IPython terminal with the current variables
(use Ctrl+D when you are finished to go back to pudb). From there you
can do any test you want. Note that if in pudb you go up in the stack
with the 'u' key and then start IPython with '!' you will have the
variables from that stack.

There are ther noce features too, such as conditional breakpoints, etc.

-- 
Darlan Cavalcante Moreira
darcamo at gmail.com



More information about the IPython-dev mailing list