Python Forum
How to programmatically stop a program in Jupyter Notebook?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to programmatically stop a program in Jupyter Notebook?
#7
(Aug-06-2021, 05:38 PM)jefsummers Wrote: Another option is wrapping in a try/except block and raising an exception. You could just raise without the try except if you dont mind seeing the traceback
try:

    for i in range(5):
        print(i)
        if i == 3:
            raise UserWarning('Exit Early')
    print('foobar')
except:
    pass

The exception is fine for me since I'm doing this for debugging purposes. It's not user-friendly, though, and there are plenty of instances where this should be useful--the most common being "do you wish to continue?"

This isn't an issue if it's the end of the code because nothing comes next and the code ends. If it's in the middle of the code then I see a void without some sort of statement that can do this. Also, AFAIK Python isn't like some other languages (BASIC, VBA) where you can have a "Goto" line that takes the program to the end for such purpose.

I feel like there's an important concept regarding all this that I have yet to learn.
Reply


Messages In This Thread
RE: How to programmatically stop a program in Jupyter Notebook? - by Mark17 - Aug-06-2021, 08:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how come i can't stop program Shi_Shi_Shi_Shi 4 688 Nov-16-2023, 06:20 PM
Last Post: deanhystad
  My code works on Jupyter Lab/Notebook, but NOT on Visual Code Editor jst 4 1,184 Nov-15-2023, 06:56 PM
Last Post: jst
  Navigating file directories and paths inside Jupyter Notebook Mark17 5 815 Oct-29-2023, 12:40 PM
Last Post: Mark17
Question How create programmatically variables ? SpongeB0B 6 1,436 Aug-19-2023, 05:10 AM
Last Post: SpongeB0B
Thumbs Up Python 3 Jupyter notebook ternary plot data nicholas 0 992 Jan-21-2023, 05:01 PM
Last Post: nicholas
  Create Excel Line Chart Programmatically dee 3 1,246 Dec-30-2022, 08:44 PM
Last Post: dee
  Graphs from Jupyter notebook to word Scott 0 929 Nov-28-2022, 06:16 AM
Last Post: Scott
  Opening an empty Jupyter notebook in VSCODE Krischu 3 1,914 Mar-09-2022, 01:57 PM
Last Post: Larz60+
  How to do line continuation in Jupyter Notebook? Mark17 4 5,584 Sep-22-2021, 04:22 PM
Last Post: ibreeden
  Jupyter Notebook as IDE bytecrunch 0 1,630 Sep-12-2021, 07:41 PM
Last Post: bytecrunch

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020