阅读下面的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(可读性):
我想读一下上面的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并将其转换为上述格式,以便调用和执行该函数。任何帮助都是非常感谢的。谢谢
试试这个:
测试:
^{pr2}$升级版:
作为代码字符串:
尝试了论坛上所有可用的方法,但不知怎么的,没有一个是我正在寻找的解决方案。因此,作为一个初学者,通过下面的非正统的查找和替换方法来解决这个问题。如果有人有更好的解决方案,请张贴它,我想使用它。在
相关问题 更多 >
编程相关推荐