python - 错误发生时如何自动启动交互式 session ?

标签 python debugging error-handling compiler-errors interactive

我通常从终端运行脚本,例如:

python script.py

有时代码运行很长时间,突然出现错误并停止正在进行的运行。不仅可以停止运行,还可以在发生错误的时候自动进入交互式 session 吗?这对于调试非常有用。

有什么建议吗?

最佳答案

我前一段时间使用以下方法解决了此问题:

from IPython import embed
...code...
embed() # Code will enter interactive session at this line
...code...

同样,try:except:的使用也非常有用。

关于python - 错误发生时如何自动启动交互式 session ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50509677/

相关文章:

python - 如何删除外部文件中的换行符?

c - 为什么我的程序不能运行?

c# - string.GetHashCode() 在调试和发布中返回不同的值,如何避免这种情况?

node.js - Node v5 破坏了 Webstorm 的调试器

asp-classic - 经典 ASP : On Error Stop

delphi - 避免在运行时出错

python - 插值到特定时间

python - 如何在python中更改对象的方法

python - 在 SQLAlchemy-ORM 中查询组合键

ios - Swift 3 转换 "has no member"错误