我们经常会需要在Spyder中查看Python中某个函数的源码,比如在这里我想查看requests模块中get函数的源码,我可以输入以下两行代码实现:
import inspect as ist print(ist.getsource(requests.get))
也就是:
import requests import inspect as ist print(ist.getsource(requests.get))
输出结果:
def get(url, params=None, **kwargs): r"""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 """ kwargs.setdefault('allow_redirects', True) return request('get', url, params=params, **kwargs)
相关文章教程推荐:spyder教程
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试