From 3fff46ec4e96b52d05ebd3eb8855f5cc37a3f5fa Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Thu, 17 Sep 2009 21:35:33 -0400 Subject: [PATCH] typos --- iterators.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iterators.html b/iterators.html index 169138d..813709b 100755 --- a/iterators.html +++ b/iterators.html @@ -372,7 +372,7 @@ rules = LazyRules()
-

Is this really nirvana? Well, yes and no. Here’s something to consider with the LazyRules exampl: the pattern file is opened (during __init__(), and it remains open until the final rule is reached. Python will evenutally close the file when it exits, or after the last instantiation of the LazyRules class is destroyed, but still, that could be a long time. If this class is part of a long-running Python process, the Python interpreter may never exit, and the LazyRules object may never get destroyed. +

Is this really nirvana? Well, yes and no. Here’s something to consider with the LazyRules example: the pattern file is opened (during __init__()), and it remains open until the final rule is reached. Python will evenutally close the file when it exits, or after the last instantiation of the LazyRules class is destroyed, but still, that could be a long time. If this class is part of a long-running Python process, the Python interpreter may never exit, and the LazyRules object may never get destroyed.

There are ways around this. Instead of opening the file during __init__() and leaving it open while you read rules one line at a time, you could open the file, read all the rules, and immediately close the file. Or you could open the file, read one rule, save the file position with the tell() method, close the file, and later re-open it and use the seek() method to continue reading where you left off. Or you could not worry about it and just leave the file open, like this example code does. Programming is design, and design is all about trade-offs and constraints. Leaving a file open too long might be a problem; making your code more complicated might be a problem. Which one is the bigger problem depends on your development team, your application, and your runtime environment.