ObjectPath: problem with the in operator

I am learning ObjectPath for python and have learned, for example, how to make an exact match on an attribute:

>>> import objectpath
>>>
>>> tree = objectpath.Tree({'doc': {'title': 'Purple is Best Color'}})
>>>
>>> tree.execute('$..*[@.title is "Purple is Best Color"]').next()
{'title': 'Purple is Best Color'}

It makes sense to me; I want to start with the root ( $) and recursively ( ..) find all ( *) elements ( @) for which title == "Purple is Best Color". And it works!

But then I will try something similar with the operator in:

>>> tree.execute('$..*["Purple" in @.title]').next()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration

A? It seemed like a natural way to tune the state, but this is not entirely correct.

, in , , , . ( , , , ). , @ ...?

, ?

+4
2

, Purple :

$..*[str("Purple") in @.title]

ObjectPath :

+7
+4

Source: https://habr.com/ru/post/1624518/


All Articles