How to Make a Python Script Exit with an Error Code
A script that checks something, such as tests, data or a model's scores, should tell the shell whether the check passed, so that a CI job or another script can stop when it didn't. That's what an exit code is for: 0 for success, anything else for failure. This guide makes a script exit with 1 when a check fails, and reads the code back in bash, zsh and PowerShell, with real output from Python 3.15.2.
