Utilize Python context managers for opening/closing files

In some of these cases, files were not being closed
This commit is contained in:
Corey Farwell 2015-08-21 11:15:17 -04:00
parent 7c45ff8e05
commit 2ab43bea5d
5 changed files with 18 additions and 21 deletions

View file

@ -47,16 +47,14 @@ def main():
parser = WebIDL.Parser(options.cachedir)
for filename in fileList:
fullPath = os.path.normpath(os.path.join(baseDir, filename))
f = open(fullPath, 'rb')
lines = f.readlines()
f.close()
with open(fullPath, 'rb') as f:
lines = f.readlines()
parser.parse(''.join(lines), fullPath)
parserResults = parser.finish()
# Write the parser results out to a pickle.
resultsFile = open('ParserResults.pkl', 'wb')
cPickle.dump(parserResults, resultsFile, -1)
resultsFile.close()
with open('ParserResults.pkl', 'wb') as resultsFile:
cPickle.dump(parserResults, resultsFile, -1)
# Load the configuration.
config = Configuration(configFile, parserResults)