From e8d7d0ac867ac020b5eb829ac629f8964a24dd55 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Sat, 1 May 2010 00:17:55 -0400 Subject: [PATCH] 2.5 --> 2.6 --- files.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files.html b/files.html index f3edefc..312632f 100644 --- a/files.html +++ b/files.html @@ -210,7 +210,7 @@ ValueError: I/O operation on closed file.

Stream objects have an explicit close() method, but what happens if your code has a bug and crashes before you call close()? That file could theoretically stay open for much longer than necessary. While you’re debugging on your local computer, that’s not a big deal. On a production server, maybe it is. -

Python 2 had a solution for this: the try..finally block. That still works in Python 3, and you may see it in other people’s code or in older code that was ported to Python 3. But Python 2.5 introduced a cleaner solution, which is now the preferred solution in Python 3: the with statement. +

Python 2 had a solution for this: the try..finally block. That still works in Python 3, and you may see it in other people’s code or in older code that was ported to Python 3. But Python 2.6 introduced a cleaner solution, which is now the preferred solution in Python 3: the with statement.

with open('examples/chinese.txt', encoding='utf-8') as a_file:
     a_file.seek(17)