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

112 Views Asked by At

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?

1

There are 1 best solutions below

0
albertopasqualetto On BEST ANSWER

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()