在 Python 中,pydoc 是做什么的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/21591572/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
In Python, what does pydoc do?
提问by logan beaupre
New to programming and python altogether. In the book I'm learning from, the author suggested I find out the purpose of Pydoc.
完全是编程和 python 的新手。在我正在学习的书中,作者建议我找出 Pydoc 的目的。
I did a google search on it, and found a match (from Gnome Terminal) but it didn't make much sense to me. Anyone mind simplifying a bit? Thanks.
我对它进行了谷歌搜索,并找到了匹配项(来自 Gnome 终端),但对我来说没有多大意义。有人介意简化一点吗?谢谢。
回答by pampasman
Pydoc is the documentation generation system for Python. Say you can document your functions using the Pydoc standard and then it can be used to generate documentation in your code.
Pydoc 是 Python 的文档生成系统。假设您可以使用 Pydoc 标准记录您的函数,然后它可以用于在您的代码中生成文档。
回答by Eric B.
It's a tool to generate python-style documentation see http://docs.python.org/2/library/pydoc.html
这是一个生成 python 样式文档的工具,请参见http://docs.python.org/2/library/pydoc.html
You may want to take a look at Sphinx too.
您可能也想看看 Sphinx。
回答by Kapil Marwaha
Pydoc is a help / documentation module for Python.
Pydoc 是 Python 的帮助/文档模块。
Use this on your Windows terminal to understand what a function in python does :
在 Windows 终端上使用它来了解 python 中的函数的作用:
python -m pydoc <function>
eg.
例如。
python -m pydoc raw_input
If the documentation for a particular function is very long, use 'q' to get out of it.
如果特定函数的文档很长,请使用“q”来摆脱它。
e.g. in case of
例如,在
python -m pydoc Tkinter
回答by Nigel
Concise description provided by to Wikipedia: "Pydoc allows Python programmers to access Python's documentation help files, generate text and HTML pages with documentation specifics, and find the appropriate module for a particular job."
维基百科提供的简明描述:“Pydoc 允许 Python 程序员访问 Python 的文档帮助文件,生成具有文档细节的文本和 HTML 页面,并为特定工作找到合适的模块。”
回答by Anilkumar
The pydoc module automatically generates documentation from Python modules. The documentation can be presented as pages of text on the console, served to a Web browser, or saved to HTML files.
pydoc 模块自动从 Python 模块生成文档。文档可以在控制台上显示为文本页面、提供给 Web 浏览器或保存为 HTML 文件。
For modules, classes, functions and methods, the displayed documentation is derived from the docstring (i.e. the docattribute) of the object, and recursively of its documentable members. If there is no docstring, pydoc tries to obtain a description from the block of comment lines just above the definition of the class, function or method in the source file, or at the top of the module.
对于模块、类、函数和方法,显示的文档是从对象的文档字符串(即doc属性)派生的,并且是其可文档成员的递归。如果没有 docstring,pydoc 会尝试从源文件中类、函数或方法定义正上方或模块顶部的注释行块中获取描述。
For more info on respective Python versions - Python 2.7- Python 3.5- Python 3.6
有关相应 Python 版本的更多信息 - Python 2.7- Python 3.5- Python 3.6
回答by Ssaa918
Just type pydoc in your terminal where you normaly run python. It will give simple explanation !. : )
只需在您通常运行 python 的终端中输入 pydoc 即可。它会给出简单的解释!:)
回答by developer
Pydoc module in Python can be used to generate documentation in the form of html pages or even on the console
Python 中的 Pydoc 模块可用于以 html 页面甚至控制台的形式生成文档
python -m pydoc 
This command gives options like view the pydoc for a file, -k search for different libraries, -p allows to open a page in web browser to view python packages, -g provides a graphical interface for looking documentation, -w writes an html output. Below are the sample commands that you can fire for testing.
此命令提供的选项包括查看文件的 pydoc、-k 搜索不同的库、-p 允许在 Web 浏览器中打开页面以查看 python 包、-g 提供用于查看文档的图形界面、-w 编写 html 输出. 以下是您可以触发以进行测试的示例命令。
python -m pydoc yourpythonfile
python -m pydoc -k ftplib
python -m pydoc -p 314
python -m pydoc -w file
I have created two sample files in a directory file1.py and file2.py which has a simple code with a single line of comment.
我在目录 file1.py 和 file2.py 中创建了两个示例文件,其中包含带有一行注释的简单代码。
def f2m(ft):
    """ Return the number of meters eq to feet """
    return 0.30 * ft
One way to see the comment of the files is to simply write below in the same file and you can run python file.py and it would show the comments.
查看文件注释的一种方法是在同一个文件中简单地写在下面,您可以运行 python file.py 并显示注释。
help(f2m)
Other way to see this is to write the command
看到这一点的另一种方法是编写命令
python -m pydoc file1
One more way to see the comments in an html page by typing this command and exporting it to html
通过键入此命令并将其导出为 html 来查看 html 页面中的评论的另一种方法
python -m pydoc -w <dir>
If you have multiple python files and if you want to generate HTML into separate folder then simple shell commands can do the job. Below code generates a folder 'htmldocs' and then generates html and moves them to this new folder. If you open any one at the right hand top corner you can see index option through which you can navigate through other pages.
如果您有多个 python 文件,并且您想将 HTML 生成到单独的文件夹中,那么简单的 shell 命令就可以完成这项工作。下面的代码生成一个文件夹 'htmldocs',然后生成 html 并将它们移动到这个新文件夹。如果您在右上角打开任何一个,您可以看到索引选项,您可以通过它浏览其他页面。
mkdir -p htmldocs
pydoc -w `find . -name '*.py'`
mv *.html htmldocs
回答by Yoko Koko
As a Python learner myself, the easiest way I can describe pydoc is that it is a command used to learn about different commands. The syntax goes as such:
作为我自己的 Python 学习者,我可以描述 pydoc 的最简单方法是它是一个用于学习不同命令的命令。语法如下:
> python -m pydoc 'function'
Example:
例子:
> python -m pydoc open
Help on built-in function open in module builtin:
有关在模块builtin 中打开的内置函数的帮助:
open(...) open(name[, mode[, buffering]]) -> file object
open(...) open(name[, mode[, buffering]]) -> 文件对象
Open a file using the file() type, returns a file object.  This is the
preferred way to open a file.  See file.__doc__ for further information. <<<
Hope that helps!
希望有帮助!
回答by prabhu
It is the tool that helps to know the word or component of a python program. i.e
它是帮助了解 Python 程序的单词或组件的工具。IE
>python -m pydoc input
To know what "input" does in code
了解“输入”在代码中的作用

