Is there a way to prevent a SystemExit exception raised from sys.exit() from being caught?

后端 未结 3 839
醉话见心
醉话见心 2020-11-29 23:58

The docs say that calling sys.exit() raises a SystemExit exception which can be caught in outer levels. I have a situation in which I want to definitively and unquestionabl

3条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 00:14

    You can also use quit, see example below:

    while True:
    print('Type exit to exit.')
    response = input()
    if response == 'exit':
        quit(0)
    print('You typed ' + response + '.')
    

提交回复
热议问题