summaryrefslogtreecommitdiff
path: root/doc/postprocess.py
diff options
context:
space:
mode:
authorSeth Troisi <sethtroisi@google.com>2020-01-21 11:32:58 -0800
committerSeth Troisi <sethtroisi@google.com>2020-01-21 11:34:58 -0800
commitb54108238dbd1ce2673a042b0b270f666ea96e29 (patch)
tree6299fd6681a589e4f7a58f8acd045e2579827d5c /doc/postprocess.py
parent19b96a1635ee93c487d69ab88ac5ea3a6a14e79e (diff)
downloadnumpy-b54108238dbd1ce2673a042b0b270f666ea96e29.tar.gz
STY: use `with open` when possible
Diffstat (limited to 'doc/postprocess.py')
-rwxr-xr-xdoc/postprocess.py10
1 files changed, 3 insertions, 7 deletions
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