在Python中,是否有可能在没有范围的情况下运行一些代码?

发布于 2025-02-13 09:10:16 字数 284 浏览 0 评论 0原文

我最喜欢的调试工具之一是启动控制台的简短代码。 但是,我有时会通过(大致)调试

try: 
    #my code
    ...
except:
    launch_console()

,这需要预测错误的位置。如果我将整个脚本包装在尝试/除外,则我将无法访问我正在调试的函数中的任何变量。

如果我可以运行该程序,并且只需在错误的情况下运行在不丢失范围的情况下运行,那将非常方便。我认为Spyder应该具有此功能,但它不起作用。

想知道是否有一些不错的方法!

One of my favorite debug tools is a short piece of code which starts up a console. I sometimes debug by means of (roughly)

try: 
    #my code
    ...
except:
    launch_console()

However, this requires anticipating where the error will be. If I enclose the entire script in a try/except, I will not have access to any variables within the function I am debugging.

It would be magnificently convenient, if I could run the program and just automatically have launch_console() run in case of an error, without losing scope. I think spyder is supposed to have this functionality, but it does not work.

Wondering if there is some nice way to do this!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文