gpt4 book ai didi

Python 处理任何异常都会给出错误 KeyboardInterrupt

转载 作者:行者123 更新时间:2023-12-01 09:12:02 26 4
gpt4 key购买 nike

代码如下:

try:
input() # I hit Ctrl+C
except Exception as e:
print(str(e))

这是回溯:

Traceback (most recent call last):
File "C:\Users\User\Desktop\test.py", line 2, in <module>
input()
KeyboardInterrupt

最佳答案

当你想捕获KeyboardInterrupt时,请明确一点:

try:
input() # I hit Ctrl+C
except Exception as e:
print(str(e))
except KeyboardInterrupt :
print 'ok, ok, terminating now...'

关于Python 处理任何异常都会给出错误 KeyboardInterrupt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51579805/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com