From f172ca867214ff2116627c7931ee8950b1e75990 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Wed, 15 Jun 2016 21:48:17 +0100 Subject: [PATCH] Use with block for file output --- gramps/gen/plug/_options.py | 85 ++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 43 deletions(-) diff --git a/gramps/gen/plug/_options.py b/gramps/gen/plug/_options.py index e1767f6f9..24de9cb18 100644 --- a/gramps/gen/plug/_options.py +++ b/gramps/gen/plug/_options.py @@ -201,55 +201,54 @@ class OptionListCollection: """ Saves the current OptionListCollection to the associated file. """ - file = open(self.filename, "w", encoding="utf-8") - file.write("\n") - file.write('\n') + with open(self.filename, "w", encoding="utf-8") as file: + file.write("\n") + file.write('\n') - self.write_common(file) + self.write_common(file) - for module_name in sorted(self.get_module_names()): # enable a diff - option_list = self.get_option_list(module_name) - module_docgen_opts = {} - for docgen_name in self.docgen_names: - module_docgen_opts[docgen_name] = [] - file.write('\n' % quoteattr(module_name)) - options = option_list.get_options() - for option_name in sorted(options.keys()): # enable a diff - option_data = options[option_name] - if isinstance(option_data, (list, tuple)): - if option_data and option_data[0] in self.docgen_names: - module_docgen_opts[option_data[0]].append( - (option_name, option_data[1])) + for module_name in sorted(self.get_module_names()): # enable a diff + option_list = self.get_option_list(module_name) + module_docgen_opts = {} + for docgen_name in self.docgen_names: + module_docgen_opts[docgen_name] = [] + file.write('\n' % quoteattr(module_name)) + options = option_list.get_options() + for option_name in sorted(options.keys()): # enable a diff + option_data = options[option_name] + if isinstance(option_data, (list, tuple)): + if option_data and option_data[0] in self.docgen_names: + module_docgen_opts[option_data[0]].append( + (option_name, option_data[1])) + else: + file.write(' \n') else: - file.write(' \n') - else: - file.write(' \n') + file.write('\n') - file.write('\n') - file.close() + file.write('\n') def parse(self): """