如何在调试时让ipdb显示更多上下文行? [英] How can I make ipdb show more lines of context while debugging?

查看:430
本文介绍了如何在调试时让ipdb显示更多上下文行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,在IPython中进行调试时, ipdb 会在上方显示一行,并在下方显示一行代码中的当前位置。

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.

推荐答案

好的,我找到了这个地方在IPython源代码中执行此操作。在我的安装中它位于

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:

更改此:

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

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

太棒了!

对于IPython 4.0.1,在debugger.py中只需添加:

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

这篇关于如何在调试时让ipdb显示更多上下文行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆