Python 对象检查器?

发布于 2024-08-05 20:26:05 字数 522 浏览 2 评论 0原文

除了使用带有 python 调试器的完全集成的 IDE(如 Eclipse)之外,是否有任何小工具可以实现此目的:

  • 运行程序时,我希望能够在某个位置挂钩(类似于插入 print 语句)并且 关闭窗口后调用带有对象检查器(树视图)的窗口
  • ,程序应该恢复

它不需要抛光,甚至不是绝对稳定,它可能是某些小部件库(如wx)的内省示例代码。不过,独立于平台就好了(不是 PyObjC 程序,或者 Windows 上的类似程序)。

有什么想法吗?

编辑: 是的,我了解 pdb,但我正在寻找所有当前对象的图形树。

尽管如此,这里还是关于如何使用 pdb 的一个很好的介绍(在本例中是在 Django 中): pdb + Django

besides from using a completely integrated IDE with debugger for python (like with Eclipse), is there any little tool for achieving this:

  • when running a program, i want to be able to hook somewhere into it (similar to inserting a print statement) and call a window with an object inspector (a tree view)
  • after closing the window, the program should resume

It doesnt need to be polished, not even absolutely stable, it could be introspection example code for some widget library like wx. Platform independent would be nice though (not a PyObjC program, or something like that on Windows).

Any Ideas ?

Edit:
Yes, i know about pdb, but I'm looking for a graphical tree of all the current objects.

Nevertheless, here is a nice introduction on how to use pdb (in this case in Django):
pdb + Django

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

半岛未凉 2024-08-12 20:26:05

Winpdb 是一个带有对象检查器的平台独立图形化 GPL Python 调试器。

它支持通过网络进行远程调试、多线程、命名空间修改、嵌入式调试、加密通信,并且速度比 pdb 快 20 倍。

其他一些功能:

  • GPL 许可证。 Winpdb 是免费软件。
  • 与 CPython 2.3 到 2.6 和 Python 3000 兼容
  • 与 wxPython 2.6 到 2.8 兼容
  • 独立于平台,并在 Ubuntu Jaunty 和 Windows XP 上进行了测试。
  • 用户界面:rpdb2 基于控制台,而 winpdb 需要 wxPython 2.6 或更高版本。

这是一个屏幕截图,显示了左上角的本地对象树。

屏幕截图
(来源:winpdb.org

Winpdb is a platform independent graphical GPL Python debugger with an object inspector.

It supports remote debugging over a network, multiple threads, namespace modification, embedded debugging, encrypted communication and is up to 20 times faster than pdb.

Some other features:

  • GPL license. Winpdb is Free Software.
  • Compatible with CPython 2.3 through 2.6 and Python 3000
  • Compatible with wxPython 2.6 through 2.8
  • Platform independent, and tested on Ubuntu Jaunty and Windows XP.
  • User Interfaces: rpdb2 is console based, while winpdb requires wxPython 2.6 or later.

Here's a screenshot that shows the local object tree at the top-left.

Screenshot
(source: winpdb.org)

囍笑 2024-08-12 20:26:05

pdb 不是窗口化的,它在控制台中运行,但它是在 Python 程序中调试的标准方法。

将其插入您想要停止的位置:

import pdb;pdb.set_trace() 

您将在标准输出上收到提示。

pdb isn't windowed, it runs in a console, but it's the standard way to debug in Python programs.

Insert this where you want to stop:

import pdb;pdb.set_trace() 

you'll get a prompt on stdout.

旧伤还要旧人安 2024-08-12 20:26:05

如果商业解决方案可以接受,Wingware 可能是满足 OP 愿望的答案(Wingware 确实有免费版本,但我认为他们不具备他所需的完整调试能力,而付费版本确实提供了这一点)。

If a commercial solution is acceptable, Wingware may be the answer to the OP's desires (Wingware does have free versions, but I don't think they have the full debugging power he requires, which the for-pay versions do provide).

陌伤浅笑 2024-08-12 20:26:05

Python 调试技术值得一读。 这是 Reddit 的评论也值得一读。我确实从布莱恩的评论中找到了一些不错的调试技巧。例如此评论此评论
当然,WingIDE 很酷(对于一般的 Python 编码和 Python 代码调试),我每天都使用它。不幸的是,WingIDE 目前还无法嵌入 IPython。

Python Debugging Techniques is worth reading. and it's Reddit's comment is worth reading too. I have really find some nice debug tricks from Brian's comment. such as this comment and this comment.
Of course, WingIDE is cool (for general Python coding and Python code debugging) and I use it everyday. unlucky for WingIDE still can't embedded a IPython at now.

向日葵 2024-08-12 20:26:05

您可以使用 ipython 和 %debug 语句。一旦你的代码崩溃,你可以添加断点,查看对象等。启动调试器的一个非常粗略的方法是在代码的某行引发异常,在ipython中运行它,类型为%debug 崩溃时。

You can use ipython, with the %debug statement. Once your code crashes, you can add breakpoints, see objects etc. A very crude way to kickoff the debugger is to raise Exception at some line of your code, run it in ipython, the type %debug when it crashes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文