How to exit program with custom code and custom message?

scruel tao scruelt at hotmail.com
Mon Mar 13 04:59:12 EDT 2023


Currently, I use `sys.exit([arg])` for exiting program and it works fine.
As described in the document:
> If another type of object is passed, None is equivalent to passing zero, and any other object is printed to stderr and results in an exit code of 1.

However, if I want to exit the program with status 0 (or any numbers else except 1) and print necessary messages before exiting, I have to write:
```python
print("message")
sys.exit()
```
So why `sys.exit` takes a list of arguments (`[arg]`) as its parameter? Rather than something like `sys.exit(code:int=0, msg:str=None)`?


More information about the Python-list mailing list