You don't understand the output of flatten_dict(). You can do this
def main(): with open('source.xml', 'r', encoding='utf-8') as f: xml_string = f.read() xml_string= xml_string.replace('�', '') #optional to remove ampersands. root = ElementTree.XML(xml_string) writer = csv.writer(open("test_out.csv", 'wt')) writer.writerows(zip(*flatten_dict(root))) if __name__ == "__main__": main()
Also main() was not called in your code, due to indentation.