如何列出 Python 2.5 模块中的方法?
我正在尝试使用用 C 编写的 Python 库,该库没有任何类型的文档。 我想使用内省至少看看模块中有哪些方法和类。 有人有一个函数或库可以用来列出模块内的函数(带有参数列表)和类(带有方法和成员变量)吗?
我发现这篇文章关于Python内省,但我很确定它不适用到Python 2.5。 谢谢您的帮助。
I'm trying to use a Python library written in C that has no documentation of any kind. I want to use introspection to at least see what methods and classes are in the modules. Does somebody have a function or library I can use to list the functions (with argument lists) and classes (with methods and member variables) within a module?
I found this article about Python introspection, but I'm pretty sure it doesn't apply to Python 2.5. Thanks for the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这也非常好:
它将打印模块的文档字符串,然后列出模块的内容,也打印它们的文档字符串。
Just this is pretty good too:
It will print the docstring for the module, then list the contents of the module, printing their docstrings too.
您提到的 Mark Pilgrim 的 第 4 章实际上确实适用于 Python 2.5(以及任何其他最新的
2.*
版本,感谢向后兼容性)。 马克没有提到帮助
,但我看到其他答案提到了。似乎没有人(包括 Mark;-)提到的一个关键点是 inspect,Python 标准库中的一个优秀模块,确实有助于高级内省。
Mark Pilgrim's chapter 4, which you mention, does actually apply just fine to Python 2.5 (and any other recent
2.*
version, thanks to backwards compatibility). Mark doesn't mentionhelp
, but I see other answers do.One key bit that nobody (including Mark;-) seems to have mentioned is inspect, an excellent module in Python's standard library that really helps with advanced introspection.
您至少可以做以下一些事情:
Here are some things you can do at least:
dir() 函数显示模块具有的所有成员。
The dir() functions shows all members a module has.