如何在Linux上看到Python文档?

时间:2012-03-22 06:56:23

标签: python linux doc

在Windows中,Python有一个chm类型的文档,阅读起来非常方便。 但在Linux中,是否有任何文件让我阅读?

9 个答案:

答案 0 :(得分:18)

在线文档

最简单的方法是使用Google访问在线文档。没有一点可以找到所有模块的所有文档。但是,一些常见的是:

如果您需要离线文档,还有其他一些可能性:

下载

您可以将文档下载为HTML或PDF:https://docs.python.org/3/download.html

当您运行Web服务器时,您可以使用HTML版本并像以前一样通过浏览器访问它。 HTML网站看起来就像你习惯的那样。甚至搜索都可以脱机使用,因为它是用JavaScript实现的。

enter image description here

是pydoc

Debian等一些发行版提供了python-doc个包。你可以通过它访问它 pydoc -p [some port number]pydoc -g。这将创建一个本地Web服务器。然后,您可以打开浏览器并查看它:

enter image description here

控制台:help(...)

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)

答案 1 :(得分:9)

答案 2 :(得分:6)

如果您使用Fedora发行版,那么yum install python-docs。其他发行版可能提供类似的包。

答案 3 :(得分:4)

最好的方法是阅读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> 

答案 4 :(得分:4)

您还可以安装Ipython以在交互模式下检查模块/对象 例如,您可以在ipython中执行此操作:

import pygame  
pygame.draw.line?

然后你得到结果doc:

  

pygame.draw.line(Surface,color,start_pos,end_pos,width = 1):返回矩形
      画一条直线段

在ipython中,您可以使用tab complition,它有助于检查某些内容。

答案 5 :(得分:2)

使用以下命令 pydoc -g

答案 6 :(得分:1)

我认为最好的选择是使用google storage

  • 加上它离线
  • 加上它还具有桌面应用程序

答案 7 :(得分:0)

由于您在互联网上利用了online python docs

答案 8 :(得分:0)

  • 系统 Ubuntu 18.04

要查看Python的离线文档,

  1. 使用python3-doc安装sudo apt install python3-doc。文档安装在/usr/share/doc/python3-doc/html
  2. 使用网络浏览器打开/usr/share/doc/python3-doc/html/index.html

文档与官方文档网站https://docs.python.org/3/

上显示的相同。