[Python-3000] Putting pdb.set_trace() in builtins?

Aahz aahz at pythoncraft.com
Thu Feb 21 16:41:32 CET 2008


On Thu, Feb 21, 2008, Barry Warsaw wrote:
> 
> So I have some particularly troublesome code that I want to set a  
> breakpoint at and start stepping through.  I usually will stick this  
> tidbit at the place I want to break:
> 
>      good_code()
>      import pdb; pdb.set_trace()
>      call_buggy_code()
> 
> In doctests it's a little ickier because I have to put that all on the  
> line where I want to break, not before it or doctest won't do the  
> right thing, e.g.:
> 
>      >>> import pdb; pdb.set_trace(); call_buggy_code()
> 
> I suggest that setting a breakpoint be done with a new built-in, e.g  
> breakpoint().  So now I would do this:
> 
>      good_code()
>      breakpoint()
>      call_buggy_code()

-0

>From my POV, this is cruft in the builtins (I mostly do web apps) -- and
I don't particularly like your suggestions for modifying the result of
breakpoint() (note that Facundo wants to use gdb).  Why not simply
inject set_trace() into the builtins in your startup code?  You can
control whether it gets injected with a DEBUG env var or something.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"All problems in computer science can be solved by another level of     
indirection."  --Butler Lampson


More information about the Python-3000 mailing list