[IPython-user] Printing breakpoint list

Jon Olav Vik jonovik@gmail....
Tue Nov 3 14:28:21 CST 2009

Nathan Huesken <ipython <at> lonely-star.org> writes:
> > > Is it somehow possible in ipython/pdb to print a list of the current
> > > breakpoints into a file?
> > 
> > Use the "break" command (with no arguments) inside the debugger.
> > http://docs.python.org/library/pdb.html#debugger-commands
> Tanks for the answer, but how do I know store the output of "break" into
> a file (or first into a variable)?

Ah, I'm sorry...I parsed your question as "print (a list of the current 
(breakpoints into a file))"... 8-)

When would you ever want to print breakpoints to a file? If you're using pdb 
programmatically to set breakpoints, you will already have access to a pdb 
instance (created with p = pdb.Pdb()). Then p.breaks is a dict of the current 
breakpoints. Otherwise, you're using the interactive debugger and can just copy 
output from the command window. Or am I missing something here?

> I also discovered:
> pdb.Pdb.get_all_breaks()


In [39]: pdb.Pdb.get_all_breaks??
    def get_all_breaks(self):
        return self.breaks

> But it just gives me:
> *** TypeError: unbound method get_all_breaks() must be called with Pdb
> instance as first argument (got nothing instead)

Yes, pdb.Pdb is just a class, you need to instantiate it with Pdb(). This 
works, kind of:
>>> pdb.Pdb().get_all_breaks()

Marginally more usefully:
>>> p = pdb.Pdb()
>>> # add some breakpoints (but how?)
>>> p.get_all_breaks()

I think this feature request, "expose IPython's pdb instance", may be 
sympathetic to your cause.
Maybe the __IP.InteractiveTB.pdb.get_all_breaks() hack could be useful to you.

Best regards,
Jon Olav

More information about the IPython-user mailing list