Bootstrap FreeKB - Python (Scripting) - Stop Halt or Exit
Python (Scripting) - Stop Halt or Exit

Updated:   |  Python (Scripting) articles

There are several built in modules that are part of the Python Standard Library included with your Python installation, such as os (Operating System) and re (Regular Expression) and sys (System).

sys.exit() can be used to stop, halt, exit the execution of a Python script. In this example, Hello will be printed, the script will be exited, meaning World will not be printed.

#!/usr/bin/python
import sys
print("Hello")
sys.exit()
print("World")

 

You can also declare the exit code, such as 0 (OK) or 1 (Fault).

#!/usr/bin/python
import sys
print("Hello")
sys.exit(0)
print("World")

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 811b84 in the box below so that we can be sure you are a human.