python文檔怎么查看?
問題描述
請教學(xué)習(xí)練習(xí)Python的過程中,經(jīng)常有些模塊下的方法記不全,或者忘記正確使用方法,或者編碼的時候報錯了這時候會想到補習(xí)一個相關(guān)的知識點,除了百度相關(guān)關(guān)鍵字外,有一個方法應(yīng)該就是查DOC文檔了。但是本地的DOC文檔都是標準庫的,如果遇到第三方庫的一些知識標準姿勢是去哪里查看呢
問題解答
回答1:調(diào)用help函數(shù),可以看到一個函數(shù)或者方法的字符串文檔。
In [1]: import requestsIn [2]: help(requests.get)Help on function get in module requests.api:get(url, params=None, **kwargs) Sends a GET request. :param url: URL for the new :class:`Request` object. :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`. :param **kwargs: Optional arguments that ``request`` takes. :return: :class:`Response <Response>` object :rtype: requests.Response
使用dir可以查看模塊或?qū)ο蠖加心切┓椒ā?/p>
In [3]: dir(requests)Out[3]:[’ConnectionError’, ’HTTPError’, ’compat’, ’cookies’, ’delete’, ’exceptions’, ’get’, ’head’, ’hooks’, ...
使用ipython+?查看
In [4]: requests.get?Type:functionString form: <function get at 0x10e6c35f0>File:/Library/Python/2.7/site-packages/requests/api.pyDefinition: requests.get(url, params=None, **kwargs)Docstring:Sends a GET request.:param url: URL for the new :class:`Request` object.:param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.:param **kwargs: Optional arguments that ``request`` takes.:return: :class:`Response <Response>` object:rtype: requests.Response
使用pydoc查看字符串文檔
? ~ python -m pydoc requestsHelp on package requests:NAME requestsFILE /Library/Python/2.7/site-packages/requests/__init__.pyDESCRIPTION requests HTTP libraryRequests is an HTTP library, written in Python, for human beings. Basic GET usage: >>> import requests >>> r = requests.get(’https://www.python.org’) >>> r.status_code 200 >>> ’Python is a programming language’ in r.content True回答2:
很多第三方庫, 都有他們自己的官網(wǎng), 例如requests庫, jinja2庫等等. 所以如果你想用的庫,剛好有他們的官網(wǎng), 可以上通過搜索他們的官網(wǎng)上去學(xué)習(xí), 但是如果很不幸沒有, 那只能通過別人的博客或者分享去學(xué)習(xí), 如果等基礎(chǔ)到一定程度, 可以去直接看他們模塊的源碼, 從中找到你需要的東西
相關(guān)文章:
1. 關(guān)docker hub上有些鏡像的tag被標記““This image has vulnerabilities””2. boot2docker無法啟動3. docker-compose中volumes的問題4. nignx - docker內(nèi)nginx 80端口被占用5. java - SSH框架中寫分頁時service層中不能注入分頁類6. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.7. dockerfile - 為什么docker容器啟動不了?8. docker容器呢SSH為什么連不通呢?9. 關(guān)于docker下的nginx壓力測試10. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?

網(wǎng)公網(wǎng)安備