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:对比文件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-24怎么修改Kafka的JVM参数?-icode9专业技术文章分享
- 2024-12-23线下车企门店如何实现线上线下融合?
- 2024-12-23鸿蒙Next ArkTS编程规范总结
- 2024-12-23物流团队冬至高效运转,哪款办公软件可助力风险评估?
- 2024-12-23优化库存,提升效率:医药企业如何借助看板软件实现仓库智能化
- 2024-12-23项目管理零负担!轻量化看板工具如何助力团队协作
- 2024-12-23电商活动复盘,为何是团队成长的核心环节?
- 2024-12-23鸿蒙Next ArkTS高性能编程实战
- 2024-12-23数据驱动:电商复盘从基础到进阶!
- 2024-12-23从数据到客户:跨境电商如何通过销售跟踪工具提升营销精准度?