Skip to main content
 首页 » 编程设计

python之urllib2.urlopen 的真正签名是什么

2024年10月25日9kuangbin

在文档中是

urllib2.urlopen(url[, data[, timeout[, cafile[, capath[, cadefault[, context]]]]]) Open the URL url, which can be either a string or a Request object.

https://docs.python.org/2/library/urllib2.html

但是在模块的代码中是:

def urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT): 

是文档有误还是在某处检测了函数?

请您参考如下方法:

这取决于 Python 版本。

该函数文档的最后一行指出:

Changed in version 2.7.9: cafile, capath, cadefault, and context were added.