What is the right way to debug in iPython notebook?

前端 未结 10 1709
不知归路
不知归路 2020-11-30 16:50

As I know, %debug magic can do debug within one cell.

However, I have function calls across multiple cells.

For example,

In[1]:          


        
10条回答
  •  醉酒成梦
    2020-11-30 17:22

    Use ipdb

    Install it via

    pip install ipdb
    

    Usage:

    In[1]: def fun1(a):
       def fun2(a):
           import ipdb; ipdb.set_trace() # debugging starts here
           return do_some_thing_about(b)
       return fun2(a)
    In[2]: fun1(1)
    

    For executing line by line use n and for step into a function use s and to exit from debugging prompt use c.

    For complete list of available commands: https://appletree.or.kr/quick_reference_cards/Python/Python%20Debugger%20Cheatsheet.pdf

提交回复
热议问题