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

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

    You can get more context by doing:

    ipdb.set_trace(context=21)
    

    (there's a bug introduced in 0.10.0 that breaks this, but it should be fixed soon)

    Permanent context size

    To permanently set context size, find the installation directory by doing

    python -c 'import ipdb; print(ipdb)'
    

    which will show you a __init__.py file. Open that file and find the line (which may also be found in IPDB's __main__.py:

    def set_trace(frame=None, context=3):
    

    change the 3 to however many context lines you want.

提交回复
热议问题