在 Windows 下,执行以下 Python 脚本时,我得到的 ERRORLEVEL 为 0 而不是预期的 2。
import sys
import scipy.io
sys.exit(2)
如果我删除 import scipy.io,我得到正确的 ERRORLEVEL 2...
知道为什么导入 scipy.io 会导致这样的问题吗?
PS: windows 7, python 2.72, scipy 0.10.1
在 sys.exit 调用之前调用 help(sys.exit) 返回以下内容(这似乎不错):
Help on built-in function exit in module sys:
exit(...)
exit([status])
Exit the interpreter by raising SystemExit(status).
If the status is omitted or None, it defaults to zero (i.e., success).
If the status is numeric, it will be used as the system exit status.
If it is another kind of object, it will be printed and the system
exit status will be one (i.e., failure).
如果我打电话
sys.exit('Something wrong')
字符串已打印,但系统仍返回 0 作为 ERRORLEVEL 而不是预期的 1。
最佳答案
这似乎是由于 SciPy 中的一个错误。以下是一些相关的门票(只有第一张仍然开放):
- http://projects.scipy.org/scipy/ticket/1314
- http://projects.scipy.org/scipy/ticket/1521
- http://projects.scipy.org/scipy/ticket/1485
一个奇怪的观察结果是
the bug disappears when importing weave.
也许尝试导入 scipy.weave
看看这个解决方法是否有帮助?
关于python:导入 scipy.io 似乎会阻止 sys.exit() 正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10615917/