【发布时间】:2016-03-28 19:53:46
【问题描述】:
读取下面的python dict或其等效的yaml并生成等效的python函数调用
mydict = {'RouteAdd': {'route_config': {'RouteConfig': {'table_name': 'my table', 'app_id': 'my app', 'nexthops': [{'NexthopInfo': {'nexthop_index': 2, 'nexthop_address': {'GatewayAddress': {'ethernet_mac': 'my mac', 'nexthop_ip': 'my ip'}}, 'if_name': 'my interface'}}]}}}}
它的 yaml(为了便于阅读):
RouteAdd:
route_config:
RouteConfig:
app_id: "my app"
nexthops:
- NexthopInfo:
if_name: "my interface"
nexthop_address:
GatewayAddress:
ethernet_mac: "my mac"
nexthop_ip: "my ip"
nexthop_index: 2
table_name: "my table"
我想阅读上述的 yaml 或 python dict 并调用如下:
RouteAdd(route_config=Routeconfig(app_id="my app",nexthops=[NexthopInfo(if_name="my interface",nexthop_address=GatewayAddress(ethernet_mac="my mac",nexthop_ip="my ip"),nexthop_index=2)],table_name="my table"))
基本上交替的层次结构是一个对象。我粘贴的是一个小剪辑。寻找一个递归函数,通过读取 yaml 或 python dict 并将其转换为上述格式,以便我可以调用和执行该函数。任何帮助深表感谢。谢谢
【问题讨论】:
标签: python object dictionary yaml