admin 管理员组文章数量: 1086019
I try my best to exmplain but if it is not clear add a comment.
I need to implement some fucntion that will take 2 arguments:
- First one contains data. Some class or dict. There is no knoledge what object is - dictionary or class
- Second is a "matcher" like PyHamcrest
The problem that I need to write matcher for some nested properties. So the function will extract nested property and apply a mather to it. But how to do that? PyHamcrest works when object is "here". Of course I can pass nested property as variable but this is not a solution. I need more generic one - define mathcers for nested properties, union all of them with and
/or
/anyOf` and check.
So for end user: it define nested properties, matcher to apply for them. Then function takes objetc and return true/false wether object mathes or not.
Something shuld work like:
matcher = or(greater_than(exist("porperty.sub_property"), 49), not(exist("porperty.sub_property"))
result = myfunction({"some_obejct": 1}, matcher)
# here result is True
I try my best to exmplain but if it is not clear add a comment.
I need to implement some fucntion that will take 2 arguments:
- First one contains data. Some class or dict. There is no knoledge what object is - dictionary or class
- Second is a "matcher" like PyHamcrest
The problem that I need to write matcher for some nested properties. So the function will extract nested property and apply a mather to it. But how to do that? PyHamcrest works when object is "here". Of course I can pass nested property as variable but this is not a solution. I need more generic one - define mathcers for nested properties, union all of them with and
/or
/anyOf` and check.
So for end user: it define nested properties, matcher to apply for them. Then function takes objetc and return true/false wether object mathes or not.
Something shuld work like:
matcher = or(greater_than(exist("porperty.sub_property"), 49), not(exist("porperty.sub_property"))
result = myfunction({"some_obejct": 1}, matcher)
# here result is True
Share
Improve this question
asked Mar 27 at 17:42
CherryCherry
33.7k74 gold badges243 silver badges395 bronze badges
1 Answer
Reset to default 0You need a function that extracts nested properties and applies PyHamcrest matchers dynamically. You can use a recursive approach or operator.attrgetter
/dict.get
for flexible access.
本文标签: How perform sql like query (may be matcher) on custom properties in python objectStack Overflow
版权声明:本文标题:How perform sql like query (may be matcher?) on custom properties in python object? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744075811a2529327.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论