IPython Notebook - early exit from cell

前端 未结 4 1397
旧巷少年郎
旧巷少年郎 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:56

    This is far from "proper" but one way to exit early is to create a runtime error. So instead of returning early from a script cleanly with exit(0) one can return uncleanly with something like

    print(variable_to_query)
    () + 1
    

    which will run the code up until this point (completing the print statement) and then fail.

提交回复
热议问题