How to view python documentation?
PHPz
PHPz 2017-05-18 10:52:51
0
2
554

In the process of learning and practicing Python, I often fail to remember all the methods in some modules, or forget to use them correctly, or report an error when coding
At this time, I will think of tutoring on a relevant knowledge point, in addition to Baidu-related key points Apart from words, one way should be to check the DOC document.
But the local DOC documents are all standard libraries. If you encounter some knowledge and standard postures of third-party libraries, where can you check them?

PHPz
PHPz

学习是最好的投资!

reply all(2)
曾经蜡笔没有小新
  • 调用help函数,可以看到一个函数或者方法的字符串文档。

In [1]: import requests

In [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 ` object
    :rtype: requests.Response
  • 使用dir可以查看模块或对象都有那些方法。

In [3]: dir(requests)
Out[3]:
['ConnectionError',
 'HTTPError',
 'compat',
 'cookies',
 'delete',
 'exceptions',
 'get',
 'head',
 'hooks',
  ...
  • 使用ipython+?查看

In [4]: requests.get?
Type:        function
String form: 
File:        /Library/Python/2.7/site-packages/requests/api.py
Definition:  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 ` object
:rtype: requests.Response
  • 使用pydoc查看字符串文档

☁  ~  python -m pydoc requests

Help on package requests:

NAME
    requests

FILE
    /Library/Python/2.7/site-packages/requests/__init__.py

DESCRIPTION
    requests HTTP library
    
    Requests 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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!