Use "with" for resource allocating operation open Signed-off-by: John Kacur <jkacur@xxxxxxxxxx> --- rteval-cmd | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/rteval-cmd b/rteval-cmd index 2c775ee52f69..4598ba514ddc 100755 --- a/rteval-cmd +++ b/rteval-cmd @@ -72,15 +72,13 @@ def summarize(repfile, xslt): isarchive = True # Load the XSLT template - xsltfp = open(xslt, "r") - xsltdoc = lxml.etree.parse(xsltfp) - xsltprs = lxml.etree.XSLT(xsltdoc) - xsltfp.close() + with open(xslt, "r") as xsltfp: + xsltdoc = lxml.etree.parse(xsltfp) + xsltprs = lxml.etree.XSLT(xsltdoc) # Load the summay.xml report - with some simple sanity checks - xmlfp = open(summaryfile, "r") - xmldoc = lxml.etree.parse(xmlfp) - xmlfp.close() + with open(summaryfile, "r") as xmlfp: + xmldoc = lxml.etree.parse(xmlfp) if xmldoc.docinfo.root_name != 'rteval': raise RuntimeError("The report doesn't seem like a rteval summary report") -- 2.36.1