diff options
Diffstat (limited to 'Doc/library/collections.rst')
-rw-r--r-- | Doc/library/collections.rst | 3 |
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:: |