【问题标题】:gremlin in python NameError not recognising functionspython NameError中的gremlin无法识别函数
【发布时间】: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


    【解决方案1】:

    如果你关注了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 来完全验证上述内容也不实际。我基于阅读文档和扫描项目源代码。

    【讨论】:

    • 谢谢我在哪里运行“statics.load_statics(globals())”,当我在我的 jupyter 笔记本中运行它时它不起作用,也不能在我的 gremlin 控制台中运行
    • @Maths12:“不起作用”并不是我真正可以使用的东西。相反会发生什么?它是 Python 代码,在你的笔记本中运行它,就像运行 from gremlin_python import ... 语句一样,不带 >>> 前缀。
    • NameError: name 'statics' is not defined
    • 名称错误提示您缺少from gremlin_python import staticsstatics.load_statics(globals()) 行只能在您导入statics 之后 运行。
    • 谢谢,由于某种原因,我确实做了那个导入;它没有被识别。我已经导入了另一种方式,现在可以使用了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-26
    • 2018-08-08
    • 2020-11-01
    • 1970-01-01
    • 2012-02-12
    • 2022-06-14
    • 2013-05-06
    相关资源
    最近更新 更多