preston.py 文件源码

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

项目:Preston 作者: Celeo 项目源码 文件源码
def find(self, **kwargs):
        """
        A helper method for navigating lists of dicts on the page.

        The kwargs parameter is used to pass requirements for matching the nested
        dictionary keys. All key-values must match.

        Args:
            kwargs - matching requirements

        Returns:
            An APIElement matching the filter or None if nothing matched
        """
        if not isinstance(self.data, collections.Iterable):
            raise CRESTException('Can not iterate on an ' + str(type(self.data)))
        for element in self.data:
            if all(element[key] == value for key, value in kwargs.items()):
                if type(element) in (dict, list):
                    return APIElement(self.url, element, self._preston)
                return element
        return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号