本文整理汇总了Python中munch.Munch.toYAML方法的典型用法代码示例。如果您正苦于以下问题:Python Munch.toYAML方法的具体用法?Python Munch.toYAML怎么用?Python Munch.toYAML使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类munch.Munch
的用法示例。
在下文中一共展示了Munch.toYAML方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NodeAPIResult
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import toYAML [as 别名]
class NodeAPIResult(object):
"""Generic representation of a result from a call to the export API.
"""
def __init__(self, data):
if "nodelist" in data:
self.nodelist = data["nodelist"]
del data["nodelist"]
if "result_shortlist" in data:
self.shortlist = APIShortlist(data["result_shortlist"])
del data["result_shortlist"]
self.info = Munch(data)
def __getitem__(self, key):
return self.info[key]
def __getattr__(self, name):
return self.info.__getattr__(name)
def iternode(self):
return imap(APINode.from_dict, (l[0] for l in self.nodelist))
def print_info(self):
print(self.info.toYAML())
示例2: test_toYAML
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import toYAML [as 别名]
def test_toYAML():
b = Munch(foo=['bar', Munch(lol=True)], hello=42)
assert yaml.safe_dump(b, default_flow_style=True) == '{foo: [bar, {lol: true}], hello: 42}\n'
assert b.toYAML(default_flow_style=True) == '{foo: [bar, {lol: true}], hello: 42}\n'
assert yaml.dump(b, default_flow_style=True) == '!munch.Munch {foo: [bar, !munch.Munch {lol: true}], hello: 42}\n'
assert b.toYAML(Dumper=yaml.Dumper, default_flow_style=True) == '!munch.Munch {foo: [bar, !munch.Munch {lol: true}], hello: 42}\n'