如何列出 Python 模块中的所有函数? [英] How to list all functions in a Python module?

查看:48
本文介绍了如何列出 Python 模块中的所有函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的系统上安装了一个 Python 模块,我希望能够看到其中有哪些函数/类/方法可用.

I have a Python module installed on my system and I'd like to be able to see what functions/classes/methods are available in it.

我想在每一个上调用 help 函数.在 Ruby 中,我可以执行诸如 ClassName.methods 之类的操作来获取该类上所有可用方法的列表.Python中有没有类似的东西?

I want to call the help function on each one. In Ruby I can do something like ClassName.methods to get a list of all the methods available on that class. Is there something similar in Python?

例如.类似:

from somemodule import foo
print(foo.methods)  # or whatever is the correct method to call

推荐答案

使用检查模块:

from inspect import getmembers, isfunction

from somemodule import foo
print(getmembers(foo, isfunction))

另见 pydoc 模块,交互式解释器中的 help() 函数和 pydoc 命令行工具可生成您需要的文档.您可以给他们提供您希望查看其文档的课程.例如,他们还可以生成 HTML 输出并将其写入磁盘.

Also see the pydoc module, the help() function in the interactive interpreter and the pydoc command-line tool which generates the documentation you are after. You can just give them the class you wish to see the documentation of. They can also generate, for instance, HTML output and write it to disk.

这篇关于如何列出 Python 模块中的所有函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆