From 14588366e563a9ac4bd935169f1256c9623a3bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Mon, 21 Sep 2015 21:47:06 -0400 Subject: [PATCH] MAINT: use with to close the file --- doc/ext/plot2rst.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/ext/plot2rst.py b/doc/ext/plot2rst.py index da6ff849..0894b24f 100644 --- a/doc/ext/plot2rst.py +++ b/doc/ext/plot2rst.py @@ -371,9 +371,8 @@ def write_example(src_name, src_dir, rst_dir, cfg): ipnotebook_name = './notebook/' + ipnotebook_name example_rst += NOTEBOOK_LINK.format(ipnotebook_name) - f = open(rst_path, 'w') - f.write(example_rst) - f.flush() + with open(rst_path, 'w') as f: + f.write(example_rst) thumb_path = thumb_dir.pjoin(src_name[:-3] + '.png') first_image_file = image_dir.pjoin(figure_list[0].lstrip('/'))