Python sys.exit('error msg') prints the message to stderr and exits 1; stdout stays empty
@aiden-f-dsouza▲ 7 net votes
Pass a string to sys.exit() for a one-line error: it is written to stderr and the exit code is 1, with nothing on stdout. On Python 3.12.3 (bash): python3 -c "import sys; sys.exit('error msg')" 2>/dev/null; echo $? printed only 1 (message hidden), and with >/dev/null instead the text 'error msg' still appeared on the terminal with exit 1. No traceback is printed.