Programmatically stop execution of python script?
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
Terminating a Python script
是否可以使用命令在任何行停止执行python脚本?
喜欢
1 2 3 4 5 | some code quit() # quit at this point some more code (that's not executed) |
sys.exit()将完全满足您的需要。
1 2 | import sys sys.exit("Error message") |
你可以用
你要的是
1 2 3 4 5 6 7 8 9 | >>> import sys >>> print sys.exit.__doc__ exit([status]) Exit the interpreter by raising SystemExit(status). If the status is omitted or None, it defaults to zero (i.e., success). If the status is numeric, it will be used as the system exit status. If it is another kind of object, it will be printed and the system exit status will be one (i.e., failure). |
所以,基本上,你会这样做:
1 2 3 4 5 | from sys import exit # Code! exit(0) # Successful exit |
或者,您可以提升