python 中的urllib2.urlopen()方法

python中,urllib2中的urlopen()方法可以这样用:

response=urllib2.urlopen("http://www.baidu.com")
html=response.read()

也可以这样用:先创建一个Request对象

request=urllib2.Request("http://www.baidu.com")
response=urllib2.urlopen(request)
html=response.read()

查看urllib2.urlopen()方法:

urlopen(url, data=None, timeout=<object object>, cafile=None, capath=None, cadefault=False, context=None)

其中并没有Request类型的参数,但是为什么可以这样用呢?

有没有人知道呢,求帮助?

看下实际的调用就知道了
实际调用的还是Request
def open(self, fullurl, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
# accept a URL or a Request object
if isinstance(fullurl, basestring):
req = Request(fullurl, data)
else:
req = fullurl
if data is not None:
req.add_data(data)

    req.timeout = timeout
    protocol = req.get_type()