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

前端 未结 6 1884
慢半拍i
慢半拍i 2021-02-01 13:08

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 b

6条回答
  •  滥情空心
    2021-02-01 13:35

    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
    

提交回复
热议问题