summaryrefslogtreecommitdiffstats
path: root/Doc/library/collections.rst
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2011-03-11 16:42:48 (GMT)
committerÉric Araujo <merwok@netwok.org>2011-03-11 16:42:48 (GMT)
commita3dd56b6cffaeee21fec6529b212fd4fa98c1ea8 (patch)
tree6b9fe78b2e36d78d159216950039a033ba9311a8 /Doc/library/collections.rst
parent17b880a5d6b64f1e7d26ec8229e8b41cdf740690 (diff)
downloadcpython-a3dd56b6cffaeee21fec6529b212fd4fa98c1ea8.zip
cpython-a3dd56b6cffaeee21fec6529b212fd4fa98c1ea8.tar.gz
cpython-a3dd56b6cffaeee21fec6529b212fd4fa98c1ea8.tar.bz2
Use with statement where it improves the documentation (closes #10461)
Diffstat (limited to 'Doc/library/collections.rst')
-rw-r--r--Doc/library/collections.rst3
1 files changed, 2 insertions, 1 deletions
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
index b6ab342..42c867d 100644
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -512,7 +512,8 @@ in Unix::
def tail(filename, n=10):
'Return the last n lines of a file'
- return deque(open(filename), n)
+ with open(filename) as f:
+ return deque(f, n)
Another approach to using deques is to maintain a sequence of recently
added elements by appending to the right and popping to the left::