From b54108238dbd1ce2673a042b0b270f666ea96e29 Mon Sep 17 00:00:00 2001 From: Seth Troisi Date: Tue, 21 Jan 2020 11:32:58 -0800 Subject: STY: use `with open` when possible --- doc/postprocess.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'doc/postprocess.py') diff --git a/doc/postprocess.py b/doc/postprocess.py index b6d067437..e4cbecf7b 100755 --- a/doc/postprocess.py +++ b/doc/postprocess.py @@ -23,18 +23,14 @@ def main(): p.error('unknown mode %s' % mode) for fn in args: - f = io.open(fn, 'r', encoding="utf-8") - try: + with io.open(fn, 'r', encoding="utf-8") as f: if mode == 'html': lines = process_html(fn, f.readlines()) elif mode == 'tex': lines = process_tex(f.readlines()) - finally: - f.close() - f = io.open(fn, 'w', encoding="utf-8") - f.write("".join(lines)) - f.close() + with io.open(fn, 'w', encoding="utf-8") as f: + f.write("".join(lines)) def process_html(fn, lines): return lines -- cgit v1.2.1