如何比较两个文件之间的差异(python字典作为一种格式)? [英] How can I compare the differences between the two files(python Dictionary as a format)?
问题描述
使用python脚本将字典的内容输出到文件中,文件名为2017-12-29.txt,文件的内容来自字典内容的输出:
Use the python script to output the contents of the dictionary to a file , the file name is 2017-12-29.txt, the content of the file from output of dictionary content :
{u'AP1': [u'i-001',u'i-002'], u'AP2': [u'i-003', u'i-004'], u'AP3': [u'i-005', u'i-006'], u'AP4': [u'i-007', u'i-008'], u'AP5': ,[u'i-009', u'i-010']}
另一个文件名是2017-12-30.txt,该文件的内容来自字典内容的输出:
another file name is 2017-12-30.txt, the content of the file from output of dictionary content :
{u'AP1': [u'i-001'], u'AP2': [u'i-003', u'i-004'], u'AP3': [u'i-005'], u'AP4': [u'i-007', u'i-008'], u'AP5': ,[u'i-009', u'i-010',u'i-011']}
如何比较两个文件之间的差异,然后将该差异导出为字典格式的另一个文件或其他格式?
How can I compare the differences between the two files , then export this difference to another file in the dictionary format or other format ?
推荐答案
使用 pprint
,运行 / usr / bin / diff -u
或 difflib 针对它们,您就完成了。
Generate output files with pprint
, run /usr/bin/diff -u
or difflib against them, and you're done.
哦,和 do 在python3中编写代码。 您会很高兴的。。
Oh, and do code this in python3. You'll be glad you did.
这篇关于如何比较两个文件之间的差异(python字典作为一种格式)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!