![]() | Ned Batchelder : Blog | Code | Text | Site My .pdbrc » Home : Blog : April 2007 |
My .pdbrcSunday 8 April 2007 When I need a Python debugger, I use the standard pdb debugger. I'm very low-tech about it: I set breakpoints by adding this line to my source: import pdb; pdb.set_trace() It's the only time I use the Python semicolon, and I always use it for this line. This breaks me into the debugger when the line is executed, and I can step, examine, and so on, from there. The one aid I have is a small .pdbrc file to define a few handy shortcuts for me: # Ned's .pdbrc This defines useful commands for printing members of expressions, members of self, and locals. Not a huge step forward, but helpful nonetheless. There are other Python debuggers, but whenever I try them, I get tangled up in configurations and connections and IDEs. PDB just works, even though it is very basic. Someday I'll find a better one, but for now it serves my needs. Update: from the comments, a link to a cool way to get more interesting helper functions into the .pdbrc file: have it read an external Python file. | |
Comments
I have found winpdb to be easy to set up and use.
Pdb is my favourite too! You're the second person I know in the world who uses pdb.
You should try epdb--it's an enhanced version of pdb with a lot of very nice features:
l and l- for moving backwards and forwards in source, and you can do: func? to get the signature of the object or func?? to get the docstring. It also has tab competion, conditional breakspoints, "until " to continue code execution until a certain point, etc.
@Tim: It might be nice, but it doesn't work on Win32 (and is very hard to find - ftp://download.rpath.com/epdb/ if you're interested)
If you use pdb with emacs, it tracks the location in the source for you, most of the time, so you don't need the step-and-list aliases.
I agree about the set_trace, but I also can't live withtout this tip for code completion:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498182
I've always felt shamefully simple by inserting "import pdb; pdb.set_trace()" into code I need to debug. Visions of sophisticated breakpoint management, Java IDE users smirking and shaking their heads, teasing whispers that there must be a *better* way of debugging python flash and fade. I won't feel that way tomorrow, though. Simple isn't only better, it's ok, too. Thanks, Ned!
>I agree about the set_trace, but I also can't live withtout this tip for code completion:
>http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498182
Thanks Paulo.
For those that want to take this trick a step further, I've submitted a patch to make this behaviour default in pdb. You can find the patch here: http://sourceforge.net/tracker/index.php?func=detail&aid=1641544&group_id=5470&atid=305470
- for k in sorted(%1.keys())
+ for k in sorted(%1)
sorted will call iter for you, and iter(dict) is approximately the same as dict.iterkeys().
Add a comment: