From c1da6cc052087c6b44d3d022e2e7e1a1fd1bd6b3 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Mon, 26 Jul 2010 21:08:34 -0500 Subject: [PATCH] use the with keyword to open the file, so that the file is properly closed --- dr.botzo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dr.botzo.py b/dr.botzo.py index 099e943..36c176e 100755 --- a/dr.botzo.py +++ b/dr.botzo.py @@ -544,8 +544,8 @@ class FactFile(Module): # open file if os.path.isfile(filename): # http://www.regexprn.com/2008/11/read-random-line-in-large-file-in.html - file = open(filename, 'r') - facts = file.readlines() + with open(filename, 'r') as file: + facts = file.readlines() to_print = facts[random.randint(0, len(facts))] # return text