albertopasqualetto
albertopasqualetto

Reputation: 107

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?

Upvotes: 1

Views: 318

Answers (1)

albertopasqualetto
albertopasqualetto

Reputation: 107

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

Upvotes: 0

Related Questions