Python - 獲取幫助信息


1- Python Manuals

自帶CHM格式的Python Manuals存放在\Python<x.x>\Doc\目錄下。
可以在IDLE界面下按F1鍵或點擊help選項下Python Docs標簽打開;也可以在通過“開始 ---》python x.x ---》Python Manuals”打開。

 

2- Module Docs

包含了python中所有內置的和已經安裝的第三方Modules文檔信息
通過“開始 ---》python x.x ---》Module Docs”打開,出現pydoc程序界面,可以在搜索框直接查找需要的內容。
也可以點擊“open browser”建立本地臨時的web server,瀏覽網頁版的文檔信息。需要關閉時,點擊“quit serving”即可。

利用pydoc手工在指定端口打開web documentation server

"python -m pydoc -p 6789" (表示打開pydoc模塊來查看python文檔,並在6789端口上啟動web server)
然后訪問http://localhost:6789/,可以看到所有已經安裝的Modules文檔信息。需要關閉時,按“ctrl+c”可以終止命令或者關閉命令界面即可。

利用pydoc在終端下查看文檔信息

在命令行執行“python -m pydoc 函數名或模塊名”,可以看到自動生成的文檔信息,按q鍵退出。
例如:查看os模塊文檔"python -m pydoc os"
例如:在當前目錄生成dir函數的HTML文檔"python -m pydoc -w dir"
在Linux下同樣適用pydoc方式查看文檔。

詳細信息請查看:https://docs.python.org/3/library/pydoc.html

 

3- help()和dir()

help([object])
Invoke the built-in help system. (This function is intended for interactive use.) If no argument is given, the interactive help system starts on the interpreter console. If the argument is a string, then the string is looked up as the name of a module, function, class, method, keyword, or documentation topic, and a help page is printed on the console. If the argument is any other kind of object, a help page on the object is generated.

  • 查看對象信息:help([object])
  • 查看所有的keyword:help("keywords")
  • 查看所有的modules:help("modules")
  • 查看常見的topics: help("topics")
  • 查看模塊,例如:help("sys")
  • 查看數據類型,例如: help("list")
  • 查看數據類型的成員方法,例如: help("list.append")

對於已定義或引入的對象,help([object])查詢不使用單引號和雙引號。對於未引入的模塊等對象,要使用單引號或雙引號。

dir([object])
Without arguments, return the list of names in the current local scope. With an argument, attempt to return a list of valid attributes for that object.
查看當前屬性及方法:dir()
查看對象的屬性及方法:>dir([object])
dir([object]) 查詢不使用單引號和雙引號。

注意:
help()函數多用來查看對象的詳細說明,按q鍵退出。dir()函數多用來查看對象的屬性方法,輸出的是列表。
使用help()和dir()之前,確定查詢的對象已被定義或引入,否則會報錯:“NameError: name is not defined”。

dir(__builtins__)  # 查看BIF(built-in functions)信息
help(input)  # 參看input()函數的幫助信息

 

4- 在線文檔

    官方文檔(https://docs.python.org/)是最具權威性質的說明和解釋,利用搜索功能(https://docs.python.org/3/search.html)可以快速獲取相關信息;

    官網中文文檔:https://docs.python.org/zh-cn/

    其他文檔:

 

5- Q&A

    SegmentFault

    Stack Overflow

 

6- 搜索與請教

Google、百度、必應、牛人等等

 

7- Python第三方庫


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM