请教一个问题

2017-04-27 17:42:30 +08:00
 fingerstyle
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 的对象?
1949 次点击
所在节点    Python
3 条回复
fingerstyle
2017-04-27 17:56:01 +08:00
已经明白了。。conn.getresponse()返回一个对象。。
pimin
2017-04-27 18:41:50 +08:00
从 C/C++编程的角度你可能明白了
但是在 Python 里,万物皆对象。
那真是极好的,大家都不用担心找不到对象啦
sinux
2017-04-27 18:54:38 +08:00
@fingerstyle #1 233333

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/357763

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX