From 73e6067c1ab5083a16150bb70aa7698a958dcd7b Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Thu, 28 Feb 2019 00:45:55 -0800 Subject: MAINT: Use with statements for opening files in distutils Not super important, but saves some lines. Only the low-hanging ones here. Found while tracking down an unrelated ResourceWarning --- numpy/distutils/command/install.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'numpy/distutils/command/install.py') diff --git a/numpy/distutils/command/install.py b/numpy/distutils/command/install.py index a1dd47755..c74ae9446 100644 --- a/numpy/distutils/command/install.py +++ b/numpy/distutils/command/install.py @@ -64,16 +64,15 @@ class install(old_install): # bdist_rpm fails when INSTALLED_FILES contains # paths with spaces. Such paths must be enclosed # with double-quotes. - f = open(self.record, 'r') - lines = [] - need_rewrite = False - for l in f: - l = l.rstrip() - if ' ' in l: - need_rewrite = True - l = '"%s"' % (l) - lines.append(l) - f.close() + with open(self.record, 'r') as f: + lines = [] + need_rewrite = False + for l in f: + l = l.rstrip() + if ' ' in l: + need_rewrite = True + l = '"%s"' % (l) + lines.append(l) if need_rewrite: self.execute(write_file, (self.record, lines), -- cgit v1.2.1