diff --git a/gramps/gen/utils/lds.py b/gramps/gen/utils/lds.py index 60b84dc26..07c77ae79 100644 --- a/gramps/gen/utils/lds.py +++ b/gramps/gen/utils/lds.py @@ -47,16 +47,15 @@ class LdsTemples(object): self.__current_temple = "" self.__tlist = [] - lds_filename = os.path.join(DATA_DIR, "lds.xml") + lds_filename = os.path.expanduser(os.path.join(DATA_DIR, "lds.xml")) try: - xml_file = open(os.path.expanduser(lds_filename), 'rb') parser = ParserCreate() parser.StartElementHandler = self.__start_element parser.EndElementHandler = self.__end_element parser.CharacterDataHandler = self.__characters - parser.ParseFile(xml_file) - xml_file.close() + with open(lds_filename, 'rb') as xml_file: + parser.ParseFile(xml_file) except Exception as msg: LOG.error(str(msg)) diff --git a/gramps/gui/tipofday.py b/gramps/gui/tipofday.py index 698536bdc..4977fae28 100644 --- a/gramps/gui/tipofday.py +++ b/gramps/gui/tipofday.py @@ -138,14 +138,13 @@ class TipParser(object): self.mylist = [] self.skip = False - xml_file = open(TIP_DATA, 'rb') self.tlist = [] parser = ParserCreate() parser.StartElementHandler = self.startElement parser.EndElementHandler = self.endElement parser.CharacterDataHandler = self.characters - parser.ParseFile(xml_file) - xml_file.close() + with open(TIP_DATA, 'rb') as xml_file: + parser.ParseFile(xml_file) def get(self): """ diff --git a/gramps/plugins/lib/libholiday.py b/gramps/plugins/lib/libholiday.py index 69696621e..1a580786c 100644 --- a/gramps/plugins/lib/libholiday.py +++ b/gramps/plugins/lib/libholiday.py @@ -325,7 +325,8 @@ class _Xml2Obj: parser.StartElementHandler = self.start_element parser.EndElementHandler = self.end_element # Parse the XML File - parser.Parse(open(filename, 'rb').read(), 1) + with open(filename, 'rb') as xml_file: + parser.ParseFile(xml_file) return self.root #------------------------------------------------------------------------