Phi*_*hil 33 python python-2.7
我知道这个问题非常简单,我知道它一定会被问到很多次,而且我在搜索引擎优化和谷歌上都进行了搜索,但我找不到答案,可能是因为我没有能力将我所寻求的内容放入一个恰当的句子.
我希望能够阅读我导入的文档.
例如,如果我通过"import x"导入x,我想运行此命令,并使用Python或ipython打印其文档.
什么是这个命令功能?
谢谢.
PS.我不是指dir(),我的意思是实际打印文档的功能,供我查看和阅读此模块x具有的功能等.
Ash*_*ary 26
您可以使用.__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)
Run Code Online (Sandbox Code Playgroud)
双方的help()
ANS __doc__
两个内置的以及我们自己的模块,做工精细:
file: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
Run Code Online (Sandbox Code Playgroud)