deepdiff:对比文件

2021/7/10 23:05:48

本文主要是介绍deepdiff:对比文件,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.安装包,pip install deepdiff

2.导入包:

from deepdiff import DeepDiff   3.     dict1 = {"aaa":"AAA","bbb":"BBB"}   dict2 = {"c":"AAA","bbb":"BBB"}   print(DeepDiff(dict1,dict2))   输入:{'dictionary_item_added': [root['c']], 'dictionary_item_removed': [root['aaa']]} 对于dict1来说 dict2新增了 key c 对于dict2来说 缺失 dict2得 key aaa   4.   dict7 = {"c":"AAA","bbb":"BBB1",'eee':[{"DDD":"1233","fff":"2344"}]}   dict6 = {"c":"AAA","bbb":"BBB2",'eee':[{"DDD":"1234","fff":"2345"}]}    print(DeepDiff(dict7,dict6))   输出:{'values_changed': {"root['bbb']": {'new_value': 'BBB2', 'old_value': 'BBB1'}, "root['eee'][0]['DDD']": {'new_value': '1234', 'old_value': '1233'}, "root['eee'][0]['fff']": {'new_value': '2345', 'old_value': '2344'}}}}}}    values值改变了   5. dict4 = {"c":"AAA","bbb":"BBB",'ee':[{"DDD":"1234","fff":"2345"}]} dict5 = {"c":"AAA","bbb":"BBB",'eee':[{"DDD":"1234","fff":"2345"}]}  print(DeepDiff(dict4,dict5))  输出: {'dictionary_item_added': [root['eee']], 'dictionary_item_removed': [root['ee']]}   key值错误   详见代码:

 

 



这篇关于deepdiff:对比文件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程