Exit to command line in Python
Posted
by fuenfundachtzig
on Stack Overflow
See other posts from Stack Overflow
or by fuenfundachtzig
Published on 2010-04-06T17:51:29Z
Indexed on
2010/04/06
17:53 UTC
Read the original article
Hit count: 371
I have a script that I want to exit early under some condition:
if not "id" in dir():
print "id not set, cannot continue"
# exit here!
# otherwise continue with the rest of the script...
print "alright..."
[ more code ]
I run this script using execfile("foo.py")
from the Python interactive prompt and I would like the script to exit going back to the command line. How do I do this? If I use sys.exit()
, the Python interpreter exits completely.
© Stack Overflow or respective owner