How to exit python script

By Eric Downing. Filed in Programming, Python, Scripting, Uncategorized, Utilities  |  
TOP del.icio.us digg

When I was trying to terminate a python script after a failure, I tried to find the nicest way to exit. The sys.exit() command provided by importing the sys library was what I found.

The function can take an optional numeric argument, usually in the range of 0-127, and with no argument it returns 0. The return code is passed back to the Operating System.

import sys
sys.exit(1)

When exit returns a non-zero value, it is considered an error.

Tags:

Leave a Reply