using ipdb to debug python code in one cell (jupyter or Ipython)

后端 未结 4 964
野的像风
野的像风 2020-12-12 11:58

I\'m using jupyter (or Ipython) notebook with firefox, and want to debug some python code in the cell. I am using \'import ipdb; ipdb.set_trace()\' as kind of breakpoint, fo

4条回答
  •  温柔的废话
    2020-12-12 12:42

    Tracer() is deprecated.

    Use:

    from IPython.core.debugger import set_trace

    and then place set_trace() where breakpoint is needed.

    from IPython.core.debugger import set_trace
    
    def add_to_life_universe_everything(x):
        answer = 42
        set_trace()
        answer += x
    
        return answer
    
    add_to_life_universe_everything(12)
    

    This works fine and brings us a little bit more comfort (e.g. syntax highlighting) than just using the built-in pdb.

    source

提交回复
热议问题