Python: using sys.exit or SystemExit differences and suggestions

后端 未结 7 783
你的背包
你的背包 2020-12-29 17:31

Reading online some programmers use sys.exit, others use SystemExit.
Sorry for the basic question:

  1. What is the difference?
  2. <
7条回答
  •  长情又很酷
    2020-12-29 18:25

    SystemExit is an exception, which basically means that your progam had a behavior such that you want to stop it and raise an error. sys.exit is the function that you can call to exit from your program, possibily giving a return code to the system.

    EDIT: they are indeed the same thing, so the only difference is in the logic behind in your program. An exception is some kind of "unwanted" behaviour, whether a call to a function is, from a programmer point of view, more of a "standard" action.

提交回复
热议问题