简体   繁体   English

在 Python 的交互式 shell 中处理没有 try 块的异常

[英]Handling exceptions without try block in Python's interactive shell

See the title of this question.看这个问题的标题。 I want to play with the exception raised in the last command.我想处理在最后一个命令中引发的异常。 _ didn't help me. _没有帮助我。 Is there anything like that?有这样的吗?

Do this:做这个:

import sys
sys.exc_info()

It will give you information about the exception.它将为您提供有关异常的信息。 It's a tuple containing the exception type, the exception instance and a traceback object.它是一个包含异常类型、异常实例和回溯对象的元组。

If your 'interactive' happens within Jupyter, check this > Jupyter magic to handle notebook exceptions如果您的“交互式”发生在 Jupyter 中,请检查此 > Jupyter magic to handle notebook exceptions

It is just beautiful.它只是美丽。

If you want to add a sound > Jupyter / Colab : Play sound with any error in any cell + Play sound after completing long running cells如果要添加声音 > Jupyter / Colab:在任何单元格中播放任何错误的声音 + 完成长时间运行的单元格后播放声音

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM