Issue #12955: Change the urlopen() examples to use context managers where appropriate.

Patch by Martin Panter.
This commit is contained in:
Berker Peksag 2015-04-12 13:52:49 +03:00
parent 8ad751e024
commit 9575e1891f
5 changed files with 38 additions and 28 deletions

View file

@ -687,7 +687,8 @@ Yes. Here's a simple example that uses urllib.request::
### connect and send the server a path
req = urllib.request.urlopen('http://www.some-server.out-there'
'/cgi-bin/some-cgi-script', data=qs)
msg, hdrs = req.read(), req.info()
with req:
msg, hdrs = req.read(), req.info()
Note that in general for percent-encoded POST operations, query strings must be
quoted using :func:`urllib.parse.urlencode`. For example, to send