2017-06-22 76 views
0

有沒有辦法來安裝python文檔,使它可以像它是一個聯機幫助? (我知道你可以下載文件的源文件,並在vim中閱讀它們,使用更少或者其他方式,但是我正在考慮少量手動操作。不想自己滾動。)閱讀終端中的Python文檔?

+0

如果你在一個交互式shell中運行蟒蛇調用它,你可以使用'help()'獲得(部分)文檔。 –

回答

3

在Debian(和派生的發行版,如Ubuntu)上安裝pydoc包。然後你可以使用pydoc whatever命令。

1

我不如果這是你想要的,但是你可以在IDLE中做的所有事情,你可以在命令行上執行。例如:

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

這樣你就可以訪問文檔

2

我不知道這是你正在尋找什麼,但Python交互式控制檯提供help命令。您可以按照以下方式使用它。

>>> 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 

這將輸出所有list方法的全部文檔。

3

這不是文檔的確切副本,但有內置的help() function

在交互式的Python會話,你剛纔叫help(whatever_you_want_to_read_about),例如:

>>> 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. 
+0

我打算將提到pydoc的答案標記爲正確,因爲它最接近聯機幫助頁,但這是我現在可能使用的最多的方法,現在我已經發現它了。 :) – Var87

+0

我同意@ Var87,特別是因爲接受的答案要求你安裝一些東西,如果你不是root的話,這不是一個選項。 'help'功能是內置的。 – rocarvaj

1

您可以使用help(Class-name/method-name/anything)。而且採用__doc__

特殊__doc__文檔字符串連接到每一個類和方法。例如,看看我輸入我的翻譯。

>>> 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.' 
>>> 

因爲每個類都有一個__doc__這是附加給它的文檔字符串你可以使用CLASS_NAME .__ doc__會給出

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