代码之家  ›  专栏  ›  技术社区  ›  K.Pil

根据条件退出Jupyter笔记本。ipynb cell

  •  1
  • K.Pil  · 技术社区  · 6 年前
    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笔记本单元。

    我得到的错误是:

    /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 
    
    0 回复  |  直到 6 年前