From 3d868e0a067bc910c258f7db6cfe8864e41cf130 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Wed, 22 Jan 2020 10:52:38 +0100 Subject: [PATCH] Use context manager for writing param_file --- lib/galaxy/tools/evaluation.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/galaxy/tools/evaluation.py b/lib/galaxy/tools/evaluation.py index 140b55d2c1c..10aab1d6246 100644 --- a/lib/galaxy/tools/evaluation.py +++ b/lib/galaxy/tools/evaluation.py @@ -584,14 +584,13 @@ class ToolEvaluator(object): if self.tool.profile < 16.04 and command and "$param_file" in command: fd, param_filename = tempfile.mkstemp(dir=directory) os.close(fd) - f = open(param_filename, "w") - for key, value in param_dict.items(): - # parameters can be strings or lists of strings, coerce to list - if not isinstance(value, list): - value = [value] - for elem in value: - f.write('%s=%s\n' % (key, elem)) - f.close() + with open(param_filename, "w") as f: + for key, value in param_dict.items(): + # parameters can be strings or lists of strings, coerce to list + if not isinstance(value, list): + value = [value] + for elem in value: + f.write('%s=%s\n' % (key, elem)) self.__register_extra_file('param_file', param_filename) return param_filename else: