pythongremlingremlinpython

addEdge with python gremling GLV - how to get syntax correct


The error:

TypeError: The child traversal of [['addV']] was not spawned anonymously - use the __ class rather than a TraversalSource to construct the child traversal

appears when trying to run the following code with python GLV

a = g.addV()
b = g.addV()
print (type(a))
print (type(b))
g.addE('foo').from_(a).to_(b).next()
#g.addE('knowing').to('b').iterate()
#g.addE("knowing").from_("a").to_("b").iterate()
a = g.addV().next()
b = g.addV().next()
print (a)
print (b)
#g.addE('foo').from(a).to(b).next()
g.V(a).addE('test').from_(V(b)).next()

works see https://stackoverflow.com/a/71068278/1497139

why is there still a .from_ necessary and not a .from?


Solution

  • Summarizing the discussion in the comments as an answer.

    1. from is a reserved word in Python. The standard TinkerPop convention is to use an underscore suffix in such cases. So in this case, to avoid a reserved word conflict, the Gremlin Python driver uses from_.
    2. In order to pass a Vertex from another query into from that other query needs to be terminated using next. So a=g.V('1').next() as an example.
    3. In recent TinkerPop versions, use of g mid-traversal was removed in favor of using an anonymous traversal (__.). So, in this case, the from_ step would be written as from_(a) , where a was previously defined as a = __.V('1')