Python: using sys.exit or SystemExit differences and suggestions

后端 未结 7 756
你的背包
你的背包 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:07

    sys.exit(s) is just shorthand for raise SystemExit(s), as described in the former's docstring; try help(sys.exit). So, instead of either one of your example programs, you can do

    sys.exit('Unable to open %s' % reference)
    

提交回复
热议问题