Terminating a Python script
问题 I am aware of the die() command in PHP which stops a script early. How can I do this in Python? 回答1: import sys sys.exit() details from the sys module documentation: sys. exit ([ arg ]) Exit from Python. This is implemented by raising the SystemExit exception, so cleanup actions specified by finally clauses of try statements are honored, and it is possible to intercept the exit attempt at an outer level. The optional argument arg can be an integer giving the exit status (defaulting to zero),