【发布时间】:2020-07-27 14:08:03
【问题描述】:
我需要该代码来编译结构 2-yaml 文件,而且我在使用 DeepDiff 对象时遇到了一些问题。
文件1:
app:
mainkey:
key1: 60
key2: 5
mainkey2:
key1: 120
key2: 5
mainkey3:
test: value
文件2:
app:
mainkey:
key1: 120
key2: 5
应用程序:
import yaml
from deepdiff import DeepDiff
with open("file1.yaml", "r") as f1:
f1 = f1.read()
f1 = yaml.safe_load(f1)
with open("file2.yaml", "r") as f2:
f2 = f2.read()
f2 = yaml.safe_load(f2)
diffs = DeepDiff(f1, f2)
print(diffs['dictionary_item_removed'])
print(type(diffs['dictionary_item_removed']))
$ python3 app.py
输出:
[root['app']['mainkey2'], root['app']['mainkey3']]
<class 'deepdiff.model.PrettyOrderedSet'>
期望:
['app']['mainkey2'], ['app']['mainkey3']
如何从 DeepDiff 对象中删除 .... root 单词?
【问题讨论】:
标签: python python-3.x dictionary diff deep-diff