V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
fingerstyle
V2EX  ›  Python

请教一个问题

  •  
  •   fingerstyle · 2017-04-27 17:42:30 +08:00 · 1928 次点击
    这是一个创建于 2549 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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
        1
    fingerstyle  
    OP
       2017-04-27 17:56:01 +08:00
    已经明白了。。conn.getresponse()返回一个对象。。
    pimin
        2
    pimin  
       2017-04-27 18:41:50 +08:00 via Android
    从 C/C++编程的角度你可能明白了
    但是在 Python 里,万物皆对象。
    那真是极好的,大家都不用担心找不到对象啦
    sinux
        3
    sinux  
       2017-04-27 18:54:38 +08:00
    @fingerstyle #1 233333
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2864 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 13:50 · PVG 21:50 · LAX 06:50 · JFK 09:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.