This one is slightly different than @CoderElijah’s
Normally, when you use exit(“”) it would show whatever you put into in red, and then say “Exit status 1” however, that is not the case in my Repl. When I use exit(“”) in my code:
else:
print("Sorry, but the number you entered is not a valid option." + "\n" + "Please try again." + "\n")
exit("Exiting...")
It just stops running, without making it red and without the “Exit status 1” message.
Even if you add exit("\033[31mExiting...\nexit status 1\033[37m"), it looks like this in the IDE (which is correct):
But then if someone runs it on the cover page, it looks like this:
My guess is that this isn’t a bug so much as a feature in the new Python template. Kinda annoying to not be able to turn off that message. Now you can.
from os import environ as e
if e["REPL_ID"] != "349e450e-f936-4e7c-8b95-dc94bf67660a":
exit("\033[31mExiting...\033[37m")
else:
exit("\033[31mExiting...\nexit status 1\033[37m")
Works for me.
Of course replace that repl ID with the ID of your repl (run echo $REPL_ID in Shell to obtain).
You can probably leave out the \033[37m part but I included it just in case (might come in handy if you’re using prybar ). It makes the text white again.
import uuid
import os
def is_cover_page():
x = os.environ["REPL_ID"]
return not (str(uuid.UUID(x, version=4)) == x)
if is_cover_page():
exit("\033[31mExiting...\033[37m")
else:
exit("\033[31mExiting...\nexit status 1\033[37m")
For the sake of minification:
from os import environ as e
is_cover_page = lambda: not (str(__import__("uuid").UUID(e["REPL_ID"], version=4)) == e["REPL_ID"])
if is_cover_page():
exit("\033[31mExiting...\033[37m")
else:
exit("\033[31mExiting...\nexit status 1\033[37m")