From 6b6a4488adc12d390c5e0c8f13829dd9bf125309 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 20 Oct 2013 07:58:57 -0400 Subject: with statements: no more finally close --HG-- branch : 4.0 --- doc/_ext/px_cleaner.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'doc') diff --git a/doc/_ext/px_cleaner.py b/doc/_ext/px_cleaner.py index a5c00ff3..24541207 100644 --- a/doc/_ext/px_cleaner.py +++ b/doc/_ext/px_cleaner.py @@ -5,17 +5,11 @@ import sys def clean_px(fname): """Clean a px file.""" - f = open(fname) - try: + with open(fname) as f: text = f.read() - finally: - f.close() text = text.lstrip() - f = open(fname, "w") - try: + with open(fname, "w") as f: f.write(text) - finally: - f.close() def clean_px_files(fnames): for fname in fnames: @@ -23,4 +17,3 @@ def clean_px_files(fnames): if __name__ == '__main__': clean_px_files(sys.argv[1:]) - -- cgit v1.2.1