在Windows系统中,Python有一种chm类型的文档,非常方便阅读。 但是在Linux系统中,是否有类似的文档可以供我阅读呢?
在Windows系统中,Python有一种chm类型的文档,非常方便阅读。 但是在Linux系统中,是否有类似的文档可以供我阅读呢?
最简单的方法是使用谷歌搜索在线文档。并没有一个单一的地方可以找到所有模块的所有文档。不过,以下是一些常见的:
如果您需要离线文档,则还有其他一些可能性:
您可以将文档下载为 HTML 或 PDF:https://docs.python.org/zh-cn/3/download.html
当您运行 web 服务器时,您可以使用 HTML 版本,并像往常一样通过浏览器访问它。HTML 网站看起来就像您习惯的一样。即使是搜索也可以离线工作,因为它是使用 JavaScript 实现的。
某些发行版(如 Debian)提供了一个 python-doc
软件包。您可以通过 pydoc -p [some port number]
或通过 pydoc -g
来访问它。这将创建一个本地 web 服务器。然后您可以打开浏览器查看:
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>
或者您可以使用一个参数来调用它,这个参数可以是任何东西(模块、类、函数、对象等),它的形式如下:
或者您可以针对想要了解的内容使用一个参数进行调用,该参数可以是任何东西(模块、类、函数、对象等)。其样式如下:
>>> 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)
pydoc
也可以不使用任何标志,此时输出将进入less
(类似于man
)。例如,尝试一下pydoc os.path
。 - dshepherdhttp://www.google.cz/search?q=linux+chm+viewer
这些文档有多种格式可用: http://docs.python.org/download.html
还有一个Python文档服务器,您可以在本地运行:http://docs.python.org/library/pydoc.html?highlight=pydoc#pydoc
yum install python-docs
命令来安装 Python 文档。其他操作系统也可能提供类似的软件包。您还可以安装Ipython以在交互模式下检查模块/对象。
例如,您可以在ipython中执行以下操作:
import pygame
pygame.draw.line?
然后你会得到结果文档:
pygame.draw.line(Surface, color, start_pos, end_pos, width=1): 返回矩形
绘制一条直线段
在ipython中,您可以使用tab键自动完成功能来检查某些内容。
$ 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>
??topic
搜索方法,可以查找所有可用库。Python有类似的东西吗? - naught101对于 Python < 3.3,请使用以下命令
pydoc -g
python -m pydoc -g
对于Python 3.3及以上版本
pydoc -b
python -m pydoc -b
要查看Python的离线文档,
sudo apt install python3-doc
安装python3-doc
。文档将被安装在/usr/share/doc/python3-doc/html
。/usr/share/doc/python3-doc/html/index.html
。这些文档与官方文档站点上的文档一样:https://docs.python.org/3/
既然你在网上,就利用一下在线 Python 文档。