【发布时间】:2019-01-07 17:21:46
【问题描述】:
我在 Jupyter 笔记本中运行 Gremlin-Pyton,由于某种原因,以下操作不起作用:
g.V().group().by().by(bothE().count())
我不断收到错误:
NameError: name 'bothE' is not defined
【问题讨论】:
标签: python graph jupyter-notebook gremlin tinkerpop
我在 Jupyter 笔记本中运行 Gremlin-Pyton,由于某种原因,以下操作不起作用:
g.V().group().by().by(bothE().count())
我不断收到错误:
NameError: name 'bothE' is not defined
【问题讨论】:
标签: python graph jupyter-notebook gremlin tinkerpop
如果你关注了typical imports listed in the documentation:
>>> from gremlin_python import statics
>>> from gremlin_python.structure.graph import Graph
>>> from gremlin_python.process.graph_traversal import __
>>> from gremlin_python.process.strategies import *
>>> from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
那么bothE 可以作为__.bothE 使用。
__ 命名空间中的方法可以添加到您的笔记本全局变量中:
>>> statics.load_statics(globals())
这样您就可以直接访问bothE,无需前缀。
引用文档:
此外,通过导入 Gremlin-Python 的静态,可以省略类前缀。
>>> statics.load_statics(globals())
和
最后,statics 包含了所有的 - 方法,因此像
.out()这样的匿名遍历可以表示如下。也就是说,没有__.-前缀。>>> g.V().repeat(out()).times(2).name.fold().toList() [[ripple, lop]]
警告:我不是 Gremlin-Python 用户,安装 Gremlin 来完全验证上述内容也不实际。我基于阅读文档和扫描项目源代码。
【讨论】:
from gremlin_python import ... 语句一样,不带 >>> 前缀。
from gremlin_python import statics。 statics.load_statics(globals()) 行只能在您导入statics 之后 运行。