Подтвердить что ты не робот

Как увидеть документ Python в Linux?

В Windows Python имеет документ типа chm, и его очень удобно читать. Но в Linux есть ли какой-нибудь документ, позволяющий мне читать?

4b9b3361

Ответ 1

Онлайн-документация

Самый простой способ - использовать Google для доступа к онлайн-документации. Нет единственной точки, где вы найдете все документы всех модулей. Однако несколько общих:

Если вам нужна автономная документация, есть еще несколько возможностей:

Загрузить

Вы можете загрузить документацию как HTML или PDF: https://docs.python.org/3/download.html

Когда у вас запущен веб-сервер, вы можете использовать HTML-версию и получить к ней доступ, поскольку вы используете ее через браузер. Сайт HTML выглядит так же, как вы привыкли. Даже поиск работает в автономном режиме, поскольку он реализован с использованием JavaScript.

enter image description here

PyDoc

Некоторые дистрибутивы, такие как Debian, предлагают пакет python-doc. Вы можете получить доступ к нему через pydoc -p [some port number] или через pydoc -g. Это создаст локальный веб-сервер. Затем вы можете открыть браузер и посмотреть на него:

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)

Ответ 3

Лучший способ - прочитать документацию, встроенную в оболочку Python.

$ 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

Если вы используете дистрибутив Fedora, то yum install python-docs. Другие дистрибутивы могут предоставлять аналогичные пакеты.

Ответ 5

Вы также можете установить Ipython для проверки модулей/объектов в интерактивном режиме.
Например, вы можете сделать это в ipython:

import pygame  
pygame.draw.line?

то вы получите результат doc:

pygame.draw.line(Поверхность, цвет, start_pos, end_pos, width = 1): return Rect
    нарисуйте отрезок прямой

В ipython вы можете использовать табуляцию, полезно для проверки чего-либо.

Ответ 6

используйте следующую команду pydoc -g