如何在 Linux 上查看 Python 文档?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9817712/
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
How do I see the Python doc on Linux?
提问by Tanky Woo
In Windows, Python has a chm type document, and it is very convenient to read. But in the Linux, is there any document let me to read?
在Windows中,Python有一个chm类型的文档,阅读起来非常方便。但是在Linux下,有什么文件可以让我阅读吗?
采纳答案by Martin Thoma
Online documentation
在线文档
The simplest way is to use Google to get to online documentation. There is no single point where you find all documentations of all modules. However, a few common ones are:
最简单的方法是使用 Google 获取在线文档。没有一个点可以找到所有模块的所有文档。但是,一些常见的是:
If you need offline documentation there are a few other possibilities:
如果您需要离线文档,还有其他一些可能性:
Download it
下载它
You can download the documentation as HTML or a PDF: https://docs.python.org/3/download.html
您可以将文档下载为 HTML 或 PDF:https: //docs.python.org/3/download.html
When you have a web server running, you can use the HTML version and access it as you are used to via a browser. The HTML site looks just like you are used to. Even the search works offline, because it is implemented with JavaScript.
当您运行 Web 服务器时,您可以使用 HTML 版本并像以前一样通过浏览器访问它。HTML 站点看起来就像您习惯的那样。甚至搜索也可以离线工作,因为它是用 JavaScript 实现的。
PyDoc
文档
Some distributions like Debian offer a python-doc
package. You can access it via
pydoc -p [some port number]
or via pydoc -g
. This will create a local web server. Then you can open your browser and have a look at it:
像 Debian 这样的一些发行版提供了一个python-doc
软件包。您可以通过pydoc -p [some port number]
或 通过访问它
pydoc -g
。这将创建一个本地 Web 服务器。然后你可以打开浏览器看看:
Console: help(...)
控制台:帮助(...)
The Python interactive console has a built-in help(...)
system. You can either invoke it without an argument:
Python 交互式控制台有一个内置help(...)
系统。您可以不带参数地调用它:
$ python
Python 2.7.5+ (default, Feb 27 2014, 19:37:08)
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> help()
Welcome to Python 2.7! This is the online help utility.
If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/2.7/tutorial/.
Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
return to the interpreter, just type "quit".
To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics". Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".
help>
or you can call it with a paramter about which you want to know something. That can be anything (a module, a class, a function, an object, ...). It looks like this:
或者你可以用一个你想知道的参数来调用它。它可以是任何东西(一个模块、一个类、一个函数、一个对象……)。它看起来像这样:
>>> a = {'b':'c'}
>>> help(a)
Help on dict object:
class dict(object)
| dict() -> new empty dictionary
| dict(mapping) -> new dictionary initialized from a mapping object's
| (key, value) pairs
| dict(iterable) -> new dictionary initialized as if via:
| d = {}
| for k, v in iterable:
| d[k] = v
| dict(**kwargs) -> new dictionary initialized with the name=value pairs
| in the keyword argument list. For example: dict(one=1, two=2)
|
| Methods defined here:
|
| __cmp__(...)
| x.__cmp__(y) <==> cmp(x,y)
|
| __contains__(...)
| D.__contains__(k) -> True if D has a key k, else False
|
| __delitem__(...)
| x.__delitem__(y) <==> del x[y]
|
| __eq__(...)
| x.__eq__(y) <==> x==y
|
| __ge__(...)
| x.__ge__(y) <==> x>=y
|
| __getattribute__(...)
| x.__getattribute__('name') <==> x.name
|
| __getitem__(...)
| x.__getitem__(y) <==> x[y]
|
| __gt__(...)
: (scroll)
回答by SpliFF
Since you're on the Internet take advantage of the online python docs.
由于您在 Internet 上,因此请利用在线 python 文档。
回答by ronakg
Best way is to read the documentation built into Python shell.
最好的方法是阅读 Python shell 中内置的文档。
$ python
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> help()
Welcome to Python 2.7! This is the online help utility.
If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/tutorial/.
Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
return to the interpreter, just type "quit".
To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics". Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".
help>
回答by Krab
http://www.google.cz/search?q=linux+chm+viewer
http://www.google.cz/search?q=linux+chm+viewer
The docs are available in various formats: http://docs.python.org/download.html
文档有多种格式:http: //docs.python.org/download.html
There is a python documentation server, which you can run locally: http://docs.python.org/library/pydoc.html?highlight=pydoc#pydoc
有一个 python 文档服务器,你可以在本地运行:http: //docs.python.org/library/pydoc.html?highlight=pydoc#pydoc
回答by wks
If you use the Fedora distribution, then yum install python-docs
. Other distributions may provide similar packages.
如果您使用 Fedora 发行版,则yum install python-docs
. 其他发行版可能提供类似的包。
回答by Ray
You can also install the Ipython to inspect the modules/objects in the interactive mode.
For example, you can do this in ipython:
您还可以安装 Ipython 以在交互模式下检查模块/对象。
例如,您可以在 ipython 中执行此操作:
import pygame
pygame.draw.line?
then you get the result doc:
然后你得到结果文档:
pygame.draw.line(Surface, color, start_pos, end_pos, width=1): return Rect
draw a straight line segment
pygame.draw.line(Surface, color, start_pos, end_pos, width=1): return Rect
绘制直线段
In ipython you can use tab complition, it's helpful for inspecting something.
在 ipython 中,您可以使用 tab complition,它有助于检查某些内容。
回答by zaki
use the following command pydoc -g
使用以下命令 pydoc -g
回答by liginity
- System Ubuntu 18.04
- 系统Ubuntu 18.04
To view offline documentation for Python,
要查看 Python 的离线文档,
- install
python3-doc
withsudo apt install python3-doc
. The documents are installed at/usr/share/doc/python3-doc/html
- Open
/usr/share/doc/python3-doc/html/index.html
with a web browser.
- 安装
python3-doc
使用sudo apt install python3-doc
。文件安装在/usr/share/doc/python3-doc/html
/usr/share/doc/python3-doc/html/index.html
使用网络浏览器打开。
The documents are just as presented on the official document site: https://docs.python.org/3/
文档与官方文档站点上提供的一样:https: //docs.python.org/3/