首页 > 解决方案 > 根据条件退出 Jupyter Notebook .ipynb 单元

问题描述

from sys import exit
import sys    
i=0
while i < 10:
   print(i)
   i=i+1
   if i==5:
      exit(0)

 print(' i do not want to print this')

基于上面的代码片段,我希望退出 Jupyter Notebook 单元。

我得到的错误是:

/usr/local/lib/python3.6/site-packages/IPython/core/interactiveshell.py:3275: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
  warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1) 

我试过了

sys.exit(0) 

但仍然无法优雅地退出执行

An exception has occurred, use %tb to see the full traceback.

SystemExit: 0 

标签: pythonjupyter-notebookipython

解决方案


推荐阅读