I have xml and i can sort within first child only. but it will through an error when the line have commented in my 1st child. it works fine if there is NO comments. can you help me here CODE root = tree.getroot() for c in root: c[:] = sorted(c, key=lambda child: (child.tag,child.get('name'))) xmlstr = ET.tostring(root, encoding="utf-8", method="xml") print(xmlstr.decode("utf-8")) ERROR c[:] = sorted(c, key=lambda child: (child.tag,child.get('name'))) TypeError: '
The error you're encountering is because you are trying to sort the child elements of `c` using a lambda function as the sorting key. The error message indicates that you cannot use the '
I have xml and i can sort within first child only. but it will through an error when the line have commented in my 1st child. it works fine if there is NO comments. can you help me here
CODE
root = tree.getroot()
for c in root:
c[:] = sorted(c, key=lambda child: (child.tag,child.get('name')))
xmlstr = ET.tostring(root, encoding="utf-8", method="xml")
print(xmlstr.decode("utf-8"))
ERROR
c[:] = sorted(c, key=lambda child: (child.tag,child.get('name')))
TypeError: '
The error you're encountering is because you are trying to sort the child elements of `c` using a lambda function as the sorting key. The error message indicates that you cannot use the '