После нескольких часов безуспешных попыток использовать objectpath в Python3-скрипте я провел следующий простой эксперимент:
>>> from objectpath import *
>>> tree=Tree({"a":1})
>>> tree.execute("$.a")
Ожидаемый результат: 1
Успех с python (2)
~$ python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from objectpath import *
>>> tree=Tree({"a":1})
>>> tree.execute("$.a")
1
>>>
Ошибка с python3:
Что-то не так с моей установкой Python3?путь к объектам в P3 не работает ни в сценариях, ни в консоли
$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from objectpath import *
>>> tree=Tree({"a":1})
>>> tree.execute("$.a")
Traceback (most recent call last):
File "/home/lisa/.local/lib/python3.6/site-
packages/objectpath/core/parser.py", line 398, in tokenize_python
yield type_map[t[0]], t[1]
KeyError: 4
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/lisa/.local/lib/python3.6/site-
packages/objectpath/core/interpreter.py", line 605, in execute
tree=self.compile(expr)
File "/home/lisa/.local/lib/python3.6/site-
packages/objectpath/core/interpreter.py", line 38, in compile
ret=EXPR_CACHE[expr]=parse(expr,self.D)
File "/home/lisa/.local/lib/python3.6/site-
packages/objectpath/core/parser.py", line 464, in parse
r=expression().getTree()
File "/home/lisa/.local/lib/python3.6/site-
packages/objectpath/core/parser.py", line 449, in expression
left=t.led(left)
File "/home/lisa/.local/lib/python3.6/site-
packages/objectpath/core/parser.py", line 264, in led
advance()
File "/home/lisa/.local/lib/python3.6/site-
packages/objectpath/core/parser.py", line 161, in advance
token=nextToken()
File "/home/lisa/.local/lib/python3.6/site-
packages/objectpath/core/parser.py", line 413, in tokenize
for ID, value in source:
File "/home/lisa/.local/lib/python3.6/site-
packages/objectpath/core/parser.py", line 405, in tokenize_python
raise SyntaxError("Syntax error")