[docs] [issue12955] urllib.request example should use "with ... as:"

Terry J. Reedy report at bugs.python.org
Sat Feb 4 02:39:18 CET 2012


Terry J. Reedy <tjreedy at udel.edu> added the comment:

Senthil:
http://docs.python.org/dev/library/contextlib.html#contextlib.closing
currently has this example:

from urllib.request import urlopen
with closing(urlopen('http://www.python.org')) as page:

which is misleading in that the object returned from urlopen
<class 'http.client.HTTPResponse'>
has __enter__ and __exit__ methods and therefore is a c.m. in itself and does not need to be wrapped in closing(). I did not really understand from your comment whether there is any need to use closing() with anything returned in urllib. 

At the moment, shelves are not C.M.s, and would make better examples, but #13896 suggests 'fixing' that also.

----------
nosy: +ncoghlan

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12955>
_______________________________________


More information about the docs mailing list