怎样在spyder中查看函数源码
我们经常会需要在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教程
来源:PY学习网:原文地址:https://www.py.cn/article.html