oo_filters.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:origin-ci-tool 作者: openshift 项目源码 文件源码
def get_attr(data, attribute=None):
        """ This looks up dictionary attributes of the form a.b.c and returns
            the value.

            If the key isn't present, None is returned.
            Ex: data = {'a': {'b': {'c': 5}}}
                attribute = "a.b.c"
                returns 5
        """
        if not attribute:
            raise errors.AnsibleFilterError("|failed expects attribute to be set")

        ptr = data
        for attr in attribute.split('.'):
            if attr in ptr:
                ptr = ptr[attr]
            else:
                ptr = None
                break

        return ptr
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号