fastmultiplication fastmultiplication - 3 months ago 31
Python Question

How can I make ipdb show more lines of context while debugging?

By default, during debugging in IPython, ipdb shows one line above and one line below the current position in code.

Is there an easy way to make the area shown a bit bigger? I'd think it would be configurable, but haven't been able to find it.

Answer

OK, I found the place in the IPython source code to do this. In my installation it's at

.../python2.7/site-packages/ipython-0.10.2-py2.7.egg/IPython/Debugger.py:327:

Change this:

def print_stack_entry(self,frame_lineno,prompt_prefix='\n-> ',
                      context = 3):

to

def print_stack_entry(self,frame_lineno,prompt_prefix='\n-> ',
                      context = 11):

It is awesome!

For IPython 4.0.1, in debugger.py just add this:

class Pdb(OldPdb):
  """Modified Pdb class, does not load readline."""

  def __init__(self,color_scheme='NoColor',completekey=None,
               stdin=None, stdout=None, context=None):
      context=20