12

我想知道是否有专门用于 Python 的像“man.py”这样的 CLI?

前任,

man.py os.system
> system(command) -> exit_status
>
> Execute the command (a string) in a subshell.
4

2 回答 2

20

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.
$
于 2012-06-09T15:22:13.653 回答
13

最简单的方法是pydoc function在 shell 上使用,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?查看文档字符串functionfunction??更详细的视图,其中包括用 python 编写的函数的完整源代码。

在普通的 python shell 中,您可以使用help(function)它。但是,在我看来,IPython 方式更舒服。

于 2012-06-09T15:21:36.180 回答