summaryrefslogtreecommitdiffstats
path: root/Doc/faq/library.rst
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2015-04-12 10:53:33 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2015-04-12 10:53:33 (GMT)
commit556e08e9b2016121e0984039c7087f52ba064297 (patch)
tree0c3dcc73147a7887a12a9d3ac75c9213fc12c914 /Doc/faq/library.rst
parent48a724fa33143bcbab2228058d3f59e1813bd49c (diff)
parent9575e1891ff533318f6dd72ab6f6bd0f9a042014 (diff)
downloadcpython-556e08e9b2016121e0984039c7087f52ba064297.zip
cpython-556e08e9b2016121e0984039c7087f52ba064297.tar.gz
cpython-556e08e9b2016121e0984039c7087f52ba064297.tar.bz2
Issue #12955: Change the urlopen() examples to use context managers where appropriate.
Patch by Martin Panter.
Diffstat (limited to 'Doc/faq/library.rst')
-rw-r--r--Doc/faq/library.rst3
1 files changed, 2 insertions, 1 deletions
diff --git a/Doc/faq/library.rst b/Doc/faq/library.rst
index d71a9b4..064728f 100644
--- a/Doc/faq/library.rst
+++ b/Doc/faq/library.rst
@@ -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