Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
383 views
in Technique[技术] by (71.8m points)

python - IPython Notebook - early exit from cell

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 not to split the cell or manually halt execution.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...