Python3目标路径…坏了?

2024-06-16 14:09:22 发布

您现在位置:Python中文网/ 问答频道 /正文

在尝试在Python3脚本中使用objectpath数小时后,我做了以下简单的实验:

>>> from objectpath import *
>>> tree=Tree({"a":1})
>>> tree.execute("$.a")

预期产量:1

python成功(2)

^{pr2}$

Python3出错:

我安装的Python3有什么问题吗? P3中的objectpath既不能在脚本中工作,也不能在控制台上工作

$ 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")

Tags: inpycoretreeparserhomelibpackages
1条回答
网友
1楼 · 发布于 2024-06-16 14:09:22

要在python3.x中运行这个,您应该pip3 install objectpath,否则它将无法工作。在

请参见下面我如何运行您的代码:

dell@dell-XPS-15-9572:~/Desktop$ pip3 install objectpath
Collecting objectpath
Downloading https://files.pythonhosted.org/packages/21/6a/ed435be72edd1d60b7363cbb38c34aff3004fee02d1c7f9f01435c318cdb/objectpath-0.5-py2.py3-none-any.whl
Installing collected packages: objectpath
Successfully installed objectpath-0.5
dell@dell-XPS-15-9572:~/Desktop$ python3
Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more 
information.
>>> from objectpath import *
>>> tree=Tree({"a":1})
>>> tree.execute("$.a")
1
>>> 

相关问题 更多 >