gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:58:53 25 4
gpt4 key购买 nike

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

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/

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