我有一个包含以下内容的yaml文件:
Filer_Po:
- description <dsc_here>
- switchport
- switchport mode private-vlan trunk promiscuous
- spanning-tree port type edge trunk
- spanning-tree bpduguard enable
- speed 10000
- flowcontrol receive on
- flowcontrol send on
- mtu 9216
- storm-control broadcast level 20.00
- switchport private-vlan trunk native vlan 1093
- switchport private-vlan trunk allowed vlan 1094,1099
- switchport private-vlan mapping trunk 1093 1094
- no lacp graceful-convergence
- no shutdown
我使用以下代码加载文件:
with open(int_cmd_file, 'r') as stream:
try:
int_cmd_dic = yaml.load(stream)
except yaml.YAMLError as exc:
print(exc)
使用命令print json.dumps(int_cmd_dic, indent=4)
我得到以下输出。
{
"Filer_Po": [
"description <dsc_here>",
"switchport",
"switchport mode private-vlan trunk promiscuous",
"speed 10000",
"no lacp graceful-convergence",
"spanning-tree port type edge trunk",
"spanning-tree bpduguard enable",
"flowcontrol receive on",
"flowcontrol send on",
"mtu 9216",
"storm-control broadcast level 20.00",
"switchport private-vlan trunk native vlan 1093",
"switchport private-vlan trunk allowed vlan 1094,1099",
"switchport private-vlan mapping trunk 1093 1094",
"no shutdown"
]
}
请注意,&#39;速度10000&#39;是列表中早于Yaml文件中定义的元素。如何维护定义的列表顺序?