summaryrefslogtreecommitdiff
path: root/Doc/tutorial/stdlib.rst
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2015-04-12 13:52:49 +0300
committerBerker Peksag <berker.peksag@gmail.com>2015-04-12 13:52:49 +0300
commit9575e1891ff533318f6dd72ab6f6bd0f9a042014 (patch)
treeb9ebbcf4b0db1eb78f209b2b5ec26a623cfda1fc /Doc/tutorial/stdlib.rst
parent8ad751e0241b7bfbdfacff017c47794b3b0a3211 (diff)
downloadcpython-git-9575e1891ff533318f6dd72ab6f6bd0f9a042014.tar.gz
Issue #12955: Change the urlopen() examples to use context managers where appropriate.
Patch by Martin Panter.
Diffstat (limited to 'Doc/tutorial/stdlib.rst')
-rw-r--r--Doc/tutorial/stdlib.rst9
1 files changed, 5 insertions, 4 deletions
diff --git a/Doc/tutorial/stdlib.rst b/Doc/tutorial/stdlib.rst
index cd73bc2596..d71598efdc 100644
--- a/Doc/tutorial/stdlib.rst
+++ b/Doc/tutorial/stdlib.rst
@@ -153,10 +153,11 @@ protocols. Two of the simplest are :mod:`urllib.request` for retrieving data
from URLs and :mod:`smtplib` for sending mail::
>>> from urllib.request import urlopen
- >>> for line in urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl'):
- ... line = line.decode('utf-8') # Decoding the binary data to text.
- ... if 'EST' in line or 'EDT' in line: # look for Eastern Time
- ... print(line)
+ >>> with urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl') as response:
+ ... for line in response:
+ ... line = line.decode('utf-8') # Decoding the binary data to text.
+ ... if 'EST' in line or 'EDT' in line: # look for Eastern Time
+ ... print(line)
<BR>Nov. 25, 09:43:32 PM EST