我知道这个问题很简单,我知道它一定被问了很多次,我在 SO 和 Google 上都进行了搜索,但我找不到答案,可能是因为我缺乏将我所寻求的东西放入的能力一个适当的句子。
我希望能够阅读我导入的文档。
例如,如果我通过“import x”导入 x,我想运行这个命令,并用 Python 或 ipython 打印它的文档。
这个命令功能是什么?
谢谢你。
PS。我不是指 dir(),我指的是实际打印文档以供我查看和阅读此模块 x 具有哪些功能等的函数。
我知道这个问题很简单,我知道它一定被问了很多次,我在 SO 和 Google 上都进行了搜索,但我找不到答案,可能是因为我缺乏将我所寻求的东西放入的能力一个适当的句子。
我希望能够阅读我导入的文档。
例如,如果我通过“import x”导入 x,我想运行这个命令,并用 Python 或 ipython 打印它的文档。
这个命令功能是什么?
谢谢你。
PS。我不是指 dir(),我指的是实际打印文档以供我查看和阅读此模块 x 具有哪些功能等的函数。
您可以使用.__doc__
功能模块的属性:
In [14]: import itertools
In [15]: print itertools.__doc__
Functional tools for creating and using iterators..........
In [18]: print itertools.permutations.__doc__
permutations(iterable[, r]) --> permutations object
Return successive r-length permutations of elements in the iterable.
permutations(range(3), 2) --> (0,1), (0,2), (1,0), (1,2), (2,0), (2,1)
在内置模块和我们自己的模块上都可以正常help()
工作:__doc__
文件:foo.py
def myfunc():
"""
this is some info on myfunc
"""
foo=2
bar=3
In [4]: help(so27.myfunc)
In [5]: import foo
In [6]: print foo.myfunc.__doc__
this is some info on func
In [7]: help(foo.myfunc)
Help on function myfunc in module foo:
myfunc()
this is some info on func
pydoc foo.bar
从命令行help(foo.bar)
或help('foo.bar')
Python。
您可以使用help()
函数来显示文档。或者您可以选择method.__doc__
描述符。
例如:help(input)
将提供有关 input() 方法的文档。