我想知道是否有类似于“man.py”这样专门为Python而设计的CLI工具?
例如:
man.py os.system
> system(command) -> exit_status
>
> Execute the command (a string) in a subshell.
我想知道是否有类似于“man.py”这样专门为Python而设计的CLI工具?
例如:
man.py os.system
> system(command) -> exit_status
>
> Execute the command (a string) in a subshell.
pydoc模块提供了它:
$ python -m pydoc os.system
Help on built-in function system in os:
os.system = system(...)
system(command) -> exit_status
Execute the command (a string) in a subshell.
$
最简单的方法是在shell上使用pydoc function
,其中function
可以是内置函数的名称或模块中函数的限定名称(module.function
):
> PAGER=cat pydoc urllib.urlencode
[adrian@hades:~]> PAGER=cat pydoc urllib.urlencode
Help on function urlencode in urllib:
urllib.urlencode = urlencode(query, doseq=0)
Encode a sequence of two-element tuples or dictionary into a URL query string.
...
(PAGER=cat
仅用于使其在此处可复制和粘贴)
在使用 IPython 时,您可以使用 function?
查看 function
的文档字符串,或者使用 function??
查看更详细的视图,其中包括使用 Python 编写的函数的完整源代码。
在普通的 Python Shell 中,您可以使用 help(function)
来实现这一点。但是,在我看来,IPython 的方法更加方便。
?function
等同于function?
。 - Vidul