Search code examples
pythonwindowsattributeerrorraise

Windows compatibility workaround for AttributeError: module 'os' has no attribute EXIT_CODE


When calling quit(os.EX_CONFIG) on Windows, it gives AttributeError: module 'os' has no attribute 'EX_CONFIG' since os.EX_CONFIG is not compatibile with Windows (like other os's exit codes).

Is there a workaround to leave it exit with the selected code on Unix, but not raise AttributeError on unsupported systems?


Solution

  • Just make a condition on the platform like the following one:

    if sys.platform.startswith('linux'):
        quit(os.EX_CONFIG)  # `os.EX_CONFIG` is only compatible with Linux
    else:
        quit()