原始 YAML 文件包含此
# tree format
treeroot:
branch1:
name: Node 1
branch1-1:
name: Node 1-1
branch2:
name: Node 2
branch2-1:
name: Node 2-1
使用 加载文件中的内容yaml.load()
并将其转储到新的 YAML 文件中后,我得到了这个:
# tree format
treeroot:
branch1:
branch1-1: {name:Node 1-1}
name: Node 1
branch2:
branch2-1: {name: Node 2-1}
name: Node 2
直接从纯 python 构建 YAML 文件的正确方法是什么?我不想自己写字符串。我想建立字典和列表。
部分的...
dataMap = {'treeroot':
{'branch2':
{'branch1-1':
{'name': 'Node 1-1'}, # should be its own level
'name': 'Node 1'
}
}
}