python 是否包含任何离线文档,例如 C 中的联机帮助页?

Does python have any offline documentation included like manpages in C?

我来自 C 背景,每当我想查看我刚做的事情的文档时,我都会使用 C man 3 thing 例如:

$ man 3 open
NAME
       open, openat — open file relative to directory file descriptor

SYNOPSIS
       #include <sys/stat.h>
       #include <fcntl.h>

       int open(const char *path, int oflag, ...);
       int openat(int fd, const char *path, int oflag, ...);

我想知道 Python 是否也有类似的东西。

问得好!

是的 python 也有,它甚至是交互式的,只需在您的终端中通过 运行 python 打开一个 python shell。

然后输入:

help(open)

你会得到这个:

open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)
    Open file and return a stream.  Raise OSError upon failure.

    file is either a text or byte string giving the name (and the path
    if the file isn't in the current working directory) of the file to
    be opened or an integer file descriptor of the file to be
    wrapped. (If a file descriptor is given, it is closed when the
    returned I/O object is closed, unless closefd is set to False.)
.
.
.

这与 C 中的联机帮助页完全一样。

也不要忘记 help(help) 了解更多信息 ;)