fastmultiplication fastmultiplication - 1 year ago 182
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 Source

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


Change this:

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


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

It is awesome!

For IPython 4.0.1, in 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):
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download