python3如何看文档

2025-12-02 0 50,440

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

推荐学习《Python教程》!

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:以上部本文内容由互联网用户自发贡献,本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。投诉邮箱:3758217903@qq.com

ZhiUp资源网 常见问题 python3如何看文档 https://www.zhiup.top/7597.html

相关