如何检查 Python 的类层次结构?
假设我有一个 X 类,我如何检查哪个是基类,以及它们的基类等?
我将 Eclipse 与 PyDev 结合使用,例如,对于 Java,您可以在类名称上键入 CTRL + T 并查看层次结构,例如:
java.lang.Object java.lang.Number java.lang.Integer
Python 可以吗?
如果在 Eclipse PyDev 中不可能,我在哪里可以找到此信息?
Assuming I have a class X, how do I check which is the base class/classes, and their base class/classes etc?
I'm using Eclipse with PyDev, and for Java for example you could type CTRL + T on a class' name and see the hierarchy, like:
java.lang.Object java.lang.Number java.lang.Integer
Is it possible for Python?
If not possible in Eclipse PyDev, where can I find this information?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
尝试
inspect.getclasstree()
。Try
inspect.getclasstree()
.按 f4 键并突出显示类名以打开层次结构视图。
Hit f4 with class name highlighted to open hierarchy view.
此外,每个类都带有一个名为
__mro__
它给出了给定类可以继承方法或属性的所有父类。从左到右阅读它们。例如:
Also, every class carries around with it an attribute called
__mro__
which gives all the parent classes from which a given class could inherit methods or attributes. Read them from left to right. For example:您还可以将类层次结构可视化为图片。
我使用 Graphviz DOT 和 pyreverse 可视化和探索大量混乱的类(示例)。
假设您想从
parso
库:如果您想查看限定的类名,例如,请将
-mn
更改为-my
。parso.python.tree.Literal
而不仅仅是Literal
。注意:
pyreverse
还通过glob<支持多个文件/code>
模式。
You can also visualize class hierarchy as a picture.
I use Graphviz DOT and pyreverse to visualize and explore a large mess of classes (an example).
Assuming you want to draw all classes from
tree.py
inparso
library:Change
-mn
to-my
if you want to see qualified class names, ex.parso.python.tree.Literal
instead of justLiteral
.Note:
pyreverse
also supports multiple files viaglob
patterns.点击 command+o,然后按 Ctrl+O 显示父层次结构
签出此博客 http://pydev.blogspot.jp/2015/03/navigating-through-your-code-when-in.html
Hit command+o, then Press Ctrl+O to show parent hierarchy
checkout this blog http://pydev.blogspot.jp/2015/03/navigating-through-your-code-when-in.html