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

前端 未结 6 1881
慢半拍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:54

    As a quick complement to https://stackoverflow.com/a/35883288/895245 this is the one liner that you generally want to add to the code you want to debug:

    __import__('ipdb').set_trace(context=21)
    

    You likely want to add a shortcut for that from your editor, e.g. for Vim snipmat I have:

    snippet ipd
        __import__('ipdb').set_trace(context=21)
    

    so I can type just ipd and it expands to the breakpoint. Then removing it is easy with dd since everything is contained in a single line.

    Feature request for ipdb to increase the default context size: https://github.com/gotcha/ipdb/issues/147

提交回复
热议问题