IPython Notebook - early exit from cell

前端 未结 4 1395
旧巷少年郎
旧巷少年郎 2020-12-13 08:14

I\'d like to programmatically exit a cell early in IPython Notebook. exit(0), however, kills the kernel.

Whats the proper way to do this? I\'d prefer n

4条回答
  •  庸人自扰
    2020-12-13 08:59

    Slightly more "proper" options:

    This will get you out of all but the worst try/except blocks.

    raise KeyboardInterrupt
    

    A little cleaner version of yours:

    assert(False)
    

    or simply:

    raise
    

    if you want to save a couple keystrokes.

提交回复
热议问题