use the with keyword to open the file, so that the file is properly closed
This commit is contained in:
parent
5927d361ef
commit
c1da6cc052
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue