如何在 python gremlin 中检索顶点的属性值

Hon*_* Bu 4 python gremlin amazon-neptune gremlinpython

这可能很容易,但我真的很难解决这个问题。我使用 gremlin python lib 和 aws neptune db。我知道顶点id,我只想获取顶点属性之一的值(python中的字符串类型),并更新它。

我尝试这样做:

print(g.V(event['securityEventManagerId']).values('sourceData'))
print(g.V(event['securityEventManagerId']).property('sourceData'))
print(g.V(event['securityEventManagerId']).property('sourceData').valueMap())
.....
Run Code Online (Sandbox Code Playgroud)

但我只是打印一些 python gremlin 对象GraphTraversal,例如,无法检索该值string

谁能帮我吗?

noa*_*621 5

您必须使用终端步骤,没有它们您的查询将不会执行。

来自 Tinkerpop文档

通常,当一个步骤连接到一个遍历时,会返回一个遍历。通过这种方式,遍历就以一种流畅的、单子的方式建立起来了。然而,有些步骤不返回遍历,而是执行遍历并返回结果。这些步骤称为最终步骤(terminal),并通过下面的示例进行解释。

对于你的情况,你应该这样做:

g.V(event['securityEventManagerId']).values('sourceData').next()
Run Code Online (Sandbox Code Playgroud)

  • 也有助于理解这个概念:http://tinkerpop.apache.org/docs/current/tutorials/the-gremlin-console/#result-iteration (3认同)