How to exit program with custom code and custom message?
Thomas Passin
list1 at tompassin.net
Tue Mar 14 00:17:25 EDT 2023
On 3/13/2023 10:34 PM, scruel tao wrote:
> Interesting, `raise SystemExit` seems to have the same behavior as `sys.exit`:
>
> ```shell
> python -c "raise SystemExit(100)"
> echo $?
> <<< 100
>
> python -c " import sys; sys.exit(100)"
> echo $?
> <<< 100
OTOH, you don't want to get too tricky:
(on Windows, obviously)
C:\Users\tom>py -c "import sys; sys.exit(type(100) == type('a'))"
C:\Users\tom>echo %ERRORLEVEL%
0
Presumably we wouldn't want to get an exit value of 0 for this case!
More information about the Python-list
mailing list