Hongli Bu
Hongli Bu

Reputation: 561

How to retrieve a property value of a vertex in python gremlin

It might be easy, but I am really struggling with this problem. I use gremlin python lib and aws neptune db. I know the vertex id, I just want to get the value(String type in python) of one of the properties of the vertex, and update it.

I have tried to do like this:

print(g.V(event['securityEventManagerId']).values('sourceData'))
print(g.V(event['securityEventManagerId']).property('sourceData'))
print(g.V(event['securityEventManagerId']).property('sourceData').valueMap())
.....

But I just print some python gremlin object like GraphTraversal, cannot retrieve the value as a string

Can anyone help me out?

Upvotes: 4

Views: 7221

Answers (2)

Eddy Wong
Eddy Wong

Reputation: 221

Here's a snippet:

for p in g.V(v).properties():
   print("key:",p.label, "| value: " ,p.value)

where v is the vertex you want to inspect.

Upvotes: 3

noam621
noam621

Reputation: 2856

You must use a terminal step, without them your query will not execute.

From tinkerpop documentation:

Typically, when a step is concatenated to a traversal a traversal is returned. In this way, a traversal is built up in a fluent, monadic fashion. However, some steps do not return a traversal, but instead, execute the traversal and return a result. These steps are known as terminal steps (terminal) and they are explained via the examples below.

In your case, you should do:

g.V(event['securityEventManagerId']).values('sourceData').next()

Upvotes: 5

Related Questions