Message144146
| Author |
Valery.Khamenya |
| Recipients |
Valery.Khamenya, docs@python, ezio.melotti, orsenthil, terry.reedy |
| Date |
2011年09月16日.18:15:25 |
| SpamBayes Score |
1.7177125e-06 |
| Marked as misclassified |
No |
| Message-id |
<1316196926.85.0.549257838458.issue12955@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Terry, Senthil, thanks, for replying to this ticket. OK, to the question:
1. @Terry, here is the full example as for CPython 2.7 I am talking about and the output:
#################
from urllib2 import Request, build_opener
request = Request('http://example.com')
with build_opener().open(request) as f:
txt = f.read()
print '%d characters fetched' % len(txt)
####################
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: addinfourl instance has no attribute '__exit__'
2. @Senthil, regarding the statement being a feature. I assume, that to open a connection, to read from a connection and to close it -- are the fundamental functions for what urllib2 was in particular created for. I was looking in docs for some hints of "canonical" way of doing this using urllib2.opener. After I have failed to find any guidance in docs, I've created this ticket. That is, I assume that no new feature is needed, but just a documented 5-lines example about a typical way of doing the above operations, especially *closing* the connection.
regards,
Valery |
|