def save_as(self, config_file): root = self.to_xml_element() et_helpers.indent(root) xml_source = ElementTree.tostring(root, encoding="utf-8") with io.open(config_file, "w", encoding="utf-8") as f: f.write(u"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n") f.write(xml_source.decode("utf-8"))