【发布时间】:2014-05-03 05:38:02
【问题描述】:
我看到有人建议在 Python 中使用 sys.exit()。 我的问题是,有没有其他方法可以退出当前脚本的执行,我的意思是终止,出现错误。
类似这样的:
sys.exit("You can not have three process at the same time.")
目前我的解决方案是:
print("You can not have three process at the same time.")
sys.exit()
【问题讨论】:
-
引发异常?对于这样的错误消息,我会写信给
sys.stderr:print('You can not have three processes at the same time.', file=sys.stderr),并使用sys.exit(1)表示错误退出代码。
标签: python error-handling