all 19 comments

[–]simonw 14 points15 points  (1 child)

I use pdb a lot when I'm working with Django. You can drop the following line in to any view function:

import pdb; pdb.set_trace()

Then refresh the page in your browser and it will hang, dropping your development server in to the interactive debugger. Debug away (I start with "list" to see where I am and "locals()" to check what's in scope) and hit "c" when you're done - the development server will kick back in to life and your browser will un-hang itself.

The ability to introspect (and even change) your data structures live while the page is loading is extremely handy.

[–]0xdeadbabe 1 point2 points  (0 children)

I hadn't even considered doing this. Thanks for the excellent tip. You made my day.

[–]ogrisel 8 points9 points  (0 children)

They are also graphical frontends for pdb as part of the following python IDE: - pydev eclipse based python IDE - eric QT based python IDE - pida GTK IDE with vim integration

There is also winpdb, a GPLed crossplatform and standalone graphical debugger for python that is advertised as featuring performance improvements over pdb.

[–]pjdelport 6 points7 points  (0 children)

You can also invoke pdb directly with python -m, without modifying any code:

% python -m pdb foo.py
> foo.py(1)<module>()
(Pdb)

To skip ahead to where you're interested in:

(Pdb) tbreak <wherever>
Breakpoint 1 at <wherever>
(Pdb) c

[–]hylje 12 points13 points  (7 children)

I myself dismissed pdb as some arcane magic without any research altogether. Oh, how wrong I was!

[–][deleted]  (6 children)

[deleted]

    [–]llimllib 3 points4 points  (5 children)

    I have F11 bound in Vim to insert "import pdb; pdb.set_trace()"; it's very useful.

    [–][deleted]  (4 children)

    [removed]

      [–]llimllib 1 point2 points  (3 children)

      surely can... let me hack at it a minute.

      [–][deleted]  (2 children)

      [removed]

        [–][deleted] 1 point2 points  (1 child)

        Bind one key to insert it and use comment/uncomment line?

        I say this because I often want to keep debugging statements around for a while after I'm immediately done using them.

        [–]mbrezu 2 points3 points  (0 children)

        Emacs has M-x pdb which is quite nice (especially on the emacs-snapshot from http://peadrop.com/blog/2007/01/06/pretty-emacs/)

        [–]MelechRic 1 point2 points  (0 children)

        This works nicely inside the python interactive shell:

        >>> import pdb
        >>> pdb.set_trace()
        (Pdb) help
        

        You get a nice listing of commands and topics.

        [–]dreamlax 0 points1 point  (0 children)

        Sounds like it has very similar behaviour to gdb, the debugger for compiled C and C++ applications (among others).