在 Windows 上调用
quit(os.EX_CONFIG)
时,它会给出 AttributeError: module 'os' has no attribute 'EX_CONFIG'
,因为 os.EX_CONFIG
与 Windows 不兼容(如其他操作系统的退出代码)。
是否有解决方法可以让它在 Unix 上以选定的代码退出,但不会在不受支持的系统上引发 AttributeError?
只需在平台上提出如下条件即可:
if sys.platform.startswith('linux'):
quit(os.EX_CONFIG) # `os.EX_CONFIG` is only compatible with Linux
else:
quit()