Possible duplicates:Programmatically stop python script execution?Python shutdown script
I want to print the value and then stop the execution of the script.
Am I just using return?
You can use the return inside the main function in which it exists, but this does not guarantee exit from the script if more code appears after your call to the main one.
The simplest one that almost always works is sys.exit() :
sys.exit()
import sys sys.exit()
Other features:
thread.interrupt_main()
The exit function in the sys ( docs ) module:
exit
sys
import sys sys.exit( 0 ) # 0 will be passed to OS
you also can
raise SystemExit
or any other exception that will not be detected.
sys.exit