Debugging Jupyter notebooks
While searching for ways to debug code in a Jupyter notebook, I found a lot of outdated posts. So I decided to quickly write up my findings. (Just show me the answer…) Let’s say we have this piece of code and we want to set a breakpoint between the original answer to the ultimate question of life, the universe and everything stored in answer and the addition to that answer: def add_to_life_universe_everything(x): answer = 42 # we want a breakpoint here answer += x return answer add_to_life_universe_everything(12) pdb The built-in Python debugger pdb works just fine in a Jupyter notebook. With import pdb; pdb.set_trace() we can enter the debugger and get a little interactive prompt. ...