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

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)
曾经蜡笔没有小新
  • Call the help function to see the string document of a function or method.

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 <Response>` object
    :rtype: requests.Response
  • Use dir to view which methods a module or object has.

In [3]: dir(requests)
Out[3]:
['ConnectionError',
 'HTTPError',
 'compat',
 'cookies',
 'delete',
 'exceptions',
 'get',
 'head',
 'hooks',
  ...
  • Use ipython+? to view

In [4]: requests.get?
Type:        function
String form: <function get at 0x10e6c35f0>
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 <Response>` object
:rtype: requests.Response
  • Use pydoc to view string documentation

☁  ~  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
为情所困

Many third-party libraries have their own official websites, such as requests library, jinja2 library, etc. So if the library you want to use happens to have their official website, you can go and learn by searching their official website, but if you are unlucky No, you can only learn from other people’s blogs or sharing. If you have a certain level of basics, you can directly look at the source code of their modules and find what you need from them

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template