推荐学习书目
› 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 · Apr 27, 2017 · 3106 views
    This topic created in 3439 days ago, the information mentioned may be changed or developed.
    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 replies  •  2017-04-27 18:54:38 +08:00
    fingerstyle
        1
    fingerstyle  
    OP
       Apr 27, 2017
    已经明白了。。conn.getresponse()返回一个对象。。
    pimin
        2
    pimin  
       Apr 27, 2017 via Android
    从 C/C++编程的角度你可能明白了
    但是在 Python 里,万物皆对象。
    那真是极好的,大家都不用担心找不到对象啦
    sinux
        3
    sinux  
       Apr 27, 2017
    @fingerstyle #1 233333
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2967 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 03:05 · PVG 11:05 · LAX 20:05 · JFK 23:05
    ♥ Do have faith in what you're doing.