Search code examples
pythoncoding-style

Exit Code Standards in Python


Are there any established exit code standards or reserved exit codes in Python (specifically, Python CLI utilities)? (e.g., /usr/include/sysexits.h for C in UNIX platforms, or http://tldp.org/LDP/abs/html/exitcodes.html for Bash scripts)


Solution

  • Provided you are on a POSIX platform, you can access the constants from sysexit.h via the os module:

    >>> import os
    >>> os.EX_ <tab pressed>
    os.EX_CANTCREAT    os.EX_NOHOST       os.EX_OK           os.EX_SOFTWARE
    os.EX_CONFIG       os.EX_NOINPUT      os.EX_OSERR        os.EX_TEMPFAIL
    os.EX_DATAERR      os.EX_NOPERM       os.EX_OSFILE       os.EX_UNAVAILABLE
    os.EX_IOERR        os.EX_NOUSER       os.EX_PROTOCOL     os.EX_USAGE