这是一个创建于 2620 天前的主题,其中的信息可能已经有所发展或是发生改变。
import http.client
conn = http.client.HTTPConnection("www.xxx.com")
conn.request("GET","/")
response = conn.getresponse()
print(response.status, response.reason)
content = response.read()
print(content)
上面的代码是一个简单的请求过程,请问 response = conn.getresponse()这里 response 是怎么成为对象的? conn.getresponse()不是 http.client 的一个方法吗? response = conn.getresponse()这样写可以让 response 成为 http.client 的对象?
3 条回复 • 2017-04-27 18:54:38 +08:00
![fingerstyle](https://cdn.v2ex.com/avatar/9f7c/2320/162762_normal.png?m=1709280085) |
|
1
fingerstyle 2017-04-27 17:56:01 +08:00
已经明白了。。conn.getresponse()返回一个对象。。
|
![pimin](https://cdn.v2ex.com/avatar/12ae/3f82/12720_normal.png?m=1459087916) |
|
2
pimin 2017-04-27 18:41:50 +08:00 via Android
从 C/C++编程的角度你可能明白了 但是在 Python 里,万物皆对象。 那真是极好的,大家都不用担心找不到对象啦
|
![sinux](https://cdn.v2ex.com/avatar/f39b/2034/111150_normal.png?m=1680504227) |
|
3
sinux 2017-04-27 18:54:38 +08:00
|