CPython implementation detail: Keys and values are listed in an arbitrary order which is non-random, varies across Python implementations, and depends on the dictionary’s history of insertions and deletions.
import filecmp
out_file = open("diff_xml_names.txt")
# Not sure what format your filenames will come in, but here's one possibility.
filePairs = [('f1a.xml', 'f1b.xml'), ('f2a.xml', 'f2b.xml'), ('f3a.xml', 'f3b.xml')]
for f1, f2 in filePairs:
if not filecmp.cmp(f1, f2):
# Files are not equal
out_file.write(f1+'\n')
out_file.close()
我想你在找^{} module 。你可以这样使用它:
用xml文件替换
f1.xml
和f2.xml
。你说的是按字节比较还是按语义相等比较? (是否
<tag attr1="1" attr2="2" />
等于<tag attr2="2" attr1="1" />
?) 如果要检查语义相等,请查看Xml comparison in Python在生成xml时,尤其是在对属性使用普通dict的情况下,有时即使使用相同的脚本和相同的输入,属性顺序也可能会混淆。
基于@Xaranke的回答:
相关问题 更多 >
编程相关推荐