Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在终端中阅读python文档?_Python_Python 3.x_Python 2.7 - Fatal编程技术网

在终端中阅读python文档?

在终端中阅读python文档?,python,python-3.x,python-2.7,Python,Python 3.x,Python 2.7,有没有一种方法可以安装python文档,使其像主页一样可用?(我知道你可以下载文档的源文件,并在vim中阅读它们,使用更少的工具或其他工具,但我正在考虑少一点手动操作。我不想自己动手。)我不知道这是否是你想要的,但你可以在空闲时做任何事情,你可以在命令行上做。例如: C:>python >>help(print()) >>help(plt.plot()) 通过这种方式,您可以访问文档我不知道这是否正是您想要的,但是python交互控制台提供了一个帮助命令。您可以按

有没有一种方法可以安装python文档,使其像主页一样可用?(我知道你可以下载文档的源文件,并在vim中阅读它们,使用更少的工具或其他工具,但我正在考虑少一点手动操作。我不想自己动手。)

我不知道这是否是你想要的,但你可以在空闲时做任何事情,你可以在命令行上做。例如:

C:>python
>>help(print())
>>help(plt.plot())

通过这种方式,您可以访问文档

我不知道这是否正是您想要的,但是python交互控制台提供了一个
帮助
命令。您可以按以下方式使用它

>>> help()

Welcome to Python 3.6's 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/3.6/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, symbols, or topics, type
"modules", "keywords", "symbols", or "topics".  Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

help> list

这将输出所有
列表
方法的完整文档。

在Debian(以及派生发行版,如Ubuntu)上安装
pydoc
包。然后您可以使用
pydoc任何
命令。

它不是文档的精确副本,但有内置的

在交互式python会话中,您只需调用
帮助(无论您想了解什么)
,例如:

>>> help(all)
Help on built-in function all in module builtins:

all(...)
    all(iterable) -> bool

    Return True if bool(x) is True for all values x in the iterable.
    If the iterable is empty, return True.

或者,您可以启动交互式帮助会话,如下所示:

C:\Users\Rawing>python -c "help()"

Welcome to Python 3.4!  This is the interactive help utility.

help>
然后只需键入您想了解的函数/类/模块:

help> all
Help on built-in function all in module builtins:

all(...)
    all(iterable) -> bool

    Return True if bool(x) is True for all values x in the iterable.
    If the iterable is empty, return True.
您可以使用
帮助(类名/方法名/任何内容)
。但也要使用\uuuuuuuuuuuuuuuuuuuu

每个类和方法都附加了一个特殊的
\uuuuudoc
docstring。例如,看看我在翻译中输入的内容

>>> print(str.__doc__)
str(object='') -> str
str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or
errors is specified, then the object must expose a data buffer
that will be decoded using the given encoding and error handler.
Otherwise, returns the result of object.__str__() (if defined)
or repr(object).
encoding defaults to sys.getdefaultencoding().
errors defaults to 'strict'.
>>> print(int.__doc__)
int(x=0) -> integer
int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments
are given.  If x is a number, return x.__int__().  For floating point
numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string,
bytes, or bytearray instance representing an integer literal in the
given base.  The literal can be preceded by '+' or '-' and be surrounded
by whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36.
Base 0 means to interpret the base from the string as an integer literal.
>>> int('0b100', base=0)
4
它甚至适用于模块

>>> import math
>>> math.__doc__
'This module is always available.  It provides access to the\nmathematical functions defined by the C standard.'
>>> math.ceil.__doc__
'ceil(x)\n\nReturn the ceiling of x as an Integral.\nThis is the smallest integer >= x.'
>>> 
因为每个类都有一个
\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

>>> print(ord.__doc__)
Return the Unicode code point for a one-character string.

您可以使用BIF帮助()

在终端中,转到类似Python的REPL

python
现在键入help()

现在,例如,如果您希望获得ipaddress
包中的类(例如IPv4Network)的帮助,则只需指定IPv4Network的完全限定路径,即ipaddress.IPv4Network

例如:

$ python3
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> help()
Welcome to Python 3.6's help utility!
help> ipaddress.IPv4Network
Help on class IPv4Network in ipaddress:

ipaddress.IPv4Network = class IPv4Network(_BaseV4, _BaseNetwork)
 |  This class represents and manipulates 32-bit IPv4 network + addresses..
 |  
 |  Attributes: [examples for IPv4Network('192.0.2.0/27')]
 |      .network_address: IPv4Address('192.0.2.0')
 |      .hostmask: IPv4Address('0.0.0.31')
 |      .broadcast_address: IPv4Address('192.0.2.32')
 |      .netmask: IPv4Address('255.255.255.224')
 |      .prefixlen: 27
 |  
 |  Method resolution order:
 |      IPv4Network
 |      _BaseV4
 |      _BaseNetwork
 |      _IPAddressBase
 |      builtins.object
 |  
 |  Methods defined here:
 |  
 |  __init__(self, address, strict=True)
 |      Instantiate a new IPv4 network object.
 |      
 |      Args:
 |          address: A string or integer representing the IP [& network].
 |            '192.0.2.0/24'
 |            '192.0.2.0/255.255.255.0'
 |            '192.0.0.2/0.0.0.255'
 |            are all functionally the same in IPv4. Similarly,
 |            '192.0.2.1'

依此类推

如果您在交互式shell中运行python,您可以使用
help()
来获取(部分)文档。我将在回答中指出pydoc是正确的,因为它最接近于手册页,但这可能是我发现它后最常用的方法。:)我同意@Var87,特别是因为公认的答案要求您安装一些东西,如果您不是root用户,这不是一个选项。
help
功能是内置的。你可以使用pydoc作为本地服务器,这样你就可以得到像python.org
pydoc-p8080这样的文档。它非常整洁,我经常在没有互联网接入的情况下使用它。就像旅行还是一件事的时候。