exit(), quit()和sys.exit()在Jupyter中不起作用



我在Jupyter中使用sys.exit()尝试一些异常消息:

import sys
input_file=input("text file here:")
try:
fhand=open(input_file)
except:
print("there is no file such this one")
sys.exit("exit file")

print(fhand)

但是我收到了一些奇怪的消息,比如

ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.
there is no file such this one
Traceback (most recent call last):
File "<ipython-input-13-337dae3e5972>", line 6, in <module>
fhand=open(input_file)

当使用exit()或quit()时,异常下面的行被打印出来,并且也有错误。
这段代码在控制台中工作得很好,所以它似乎与ipython和jupyter有关。

有什么想法吗?谢谢!

与某些包中出现错误时的情况相同:

raise(ValueError)

最新更新