相关疑难解决方法(0)

如何列出Python模块中的所有函数?

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

我想在每一个上调用doc函数.在ruby中,我可以执行类似ClassName.methods的操作,以获取该类上可用的所有方法的列表.python中有类似的东西吗?

例如.就像是:

from somemodule import foo
print foo.methods # or whatever is the correct method to call
Run Code Online (Sandbox Code Playgroud)

python reflection module inspect

376
推荐指数
13
解决办法
59万
查看次数

python:如何获取有关函数的信息?

当需要有关类型的信息时,您可以使用:

my_list = []
dir(my_list)
Run Code Online (Sandbox Code Playgroud)

得到:

['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
Run Code Online (Sandbox Code Playgroud)

要么:

dir(my_list)[36:]
Run Code Online (Sandbox Code Playgroud)

得到:

['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
Run Code Online (Sandbox Code Playgroud)

现在,在Python的文档中可以找到有关这些函数的信息,但我想在终端/命令行中获取有关这些函数的信息.该怎么做?

python methods function

55
推荐指数
2
解决办法
14万
查看次数

标签 统计

python ×2

function ×1

inspect ×1

methods ×1

module ×1

reflection ×1