How to terminate a Python script

前端 未结 10 1080
予麋鹿
予麋鹿 2020-11-22 04:34

I am aware of the die() command in PHP which exits a script early.

How can I do this in Python?

10条回答
  •  别那么骄傲
    2020-11-22 05:09

    You can also use simply exit().

    Keep in mind that sys.exit(), exit(), quit(), and os._exit(0) kill the Python interpreter. Therefore, if it appears in a script called from another script by execfile(), it stops execution of both scripts.

    See "Stop execution of a script called with execfile" to avoid this.

提交回复
热议问题