我看到有人建议在 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.exit
将起作用。 docs明确提及此用途:
In particular, sys.exit("some error message") is a quick way to exit a program when an error occurs.
关于python - 如何在python中抛出错误并使用自定义消息退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22633544/