From 431a329e2b1dbec33998c33286ca77265b49c57f Mon Sep 17 00:00:00 2001 From: Radovan Bast Date: Sun, 10 Apr 2016 16:49:32 +0200 Subject: [PATCH] use with statement for I/O --- lib/config.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/config.py b/lib/config.py index a635d40..84e8b2a 100644 --- a/lib/config.py +++ b/lib/config.py @@ -101,9 +101,8 @@ def run_cmake(command, build_path, default_build_path): # print cmake output to screen print(stdout) # write cmake output to file - f = open('cmake_output', 'w') - f.write(stdout) - f.close() + with open('cmake_output', 'w') as f: + f.write(stdout) # change directory and return os.chdir(topdir) if 'Configuring incomplete' in stdout: @@ -136,9 +135,8 @@ def save_setup_command(argv, build_path): Save setup command to a file. """ file_name = os.path.join(build_path, 'setup_command') - f = open(file_name, 'w') - f.write(' '.join(argv[:]) + '\n') - f.close() + with open(file_name, 'w') as f: + f.write(' '.join(argv[:]) + '\n') def configure(root_directory, build_path, cmake_command, only_show):