Exit pdb Interactive Mode from Jupyter Notebook

会有一股神秘感。 提交于 2019-12-07 08:15:11

问题


Within pdb, I'm using the interact command to enter interactive mode (documentation at https://docs.python.org/3/library/pdb.html). This gives me an InteractiveConsole within pdb (which I need in order to do list comprehension). From within a Jupyter Notebook, how do I leave interactive mode without exiting the debugger entirely?

Things I've tried:

  • The link below answers this exact question but the solutions only work from the terminal. Ctrl-d from within Jupyter just adds a bookmark...And quit() returns: NameError: name 'quit' is not defined

In the Python debugger pdb, how do you exit interactive mode without terminating the debugging session

  • Meditating. Situation unchanged.

I can do import sys; sys.exit(), but that exits the debugger entirely, meaning I have to start from scratch.


回答1:


The only way I have been success is to copy/paste the Crtl-D character from another source. I use Emacs, so this is fairly easy, but any text editor that allows you to insert a Crtl-D into the document should work. Once inserted, use the standard copy/paste into the pdb interact field and hit or . This should get you out.

For Emacs, the long way is as follows, for demonstration purposes:

M-x insert char <RET> END OF TRANSMISSION <RET>

At this point you should see ^D in the buffer. At this point select the character and M-w or kill-ring-save to put it on the clipboard.

Then, change to the browser and make the interactive field active, and paste the character back. You will not see anything. Then hit . This should/might get you out.



来源:https://stackoverflow.com/questions/47522316/exit-pdb-interactive-mode-from-jupyter-notebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!