» pip install xmldiff
Remove the file xml.py or a directory xml with a file __init__.py in it from your current directory and try again. Python will search the current directory first when importing modules. A file named xml.py or a package named xml in the current directory shadows the standard library package with the same name.
As pointed out in a comment by KeshV, you also need to remove the file xml.pyc, if it exists. In Python 2 it will be in the same directory as xml.py. In Python 3 it will be in the sub directory __pycache__. In General, as long as the *.py file is around, you can savely delete the corresponding *.pyc file because Python will re-create it upon import of the *.py file.
Your script name is: xml.py?
Change it and it should work.
Use the xmldiff to perform this exact task.
main.py
from xmldiff import main
diff = main.diff_files("file1.xml", "file2.xml")
print(diff)
output
[DeleteNode(node='/ngs_sample/results/gastro_prelim_st/type[2]')]
You can switch to the XMLFormatter and manually filter out the results:
...
# Change formatter:
formatter = formatting.XMLFormatter(normalize=formatting.WS_BOTH)
...
# after `out` has been retrieved:
import re
for i in out.splitlines():
if re.search(r'\bdiff:\w+', i):
print(i)
# Result:
# <type st="9999" diff:delete=""/>