Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use "neq" in Gremlin-Python?

Tags:

python

gremlin

I have a Gremlin query which works from Gremlin console

g.V("p1").as("this").out("ContributedTo").in("ContributedTo").where(neq("this")).groupCount()

I want to use it from a Python script

from __future__ import print_function  # Python 2/3 compatibility

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

graph = Graph()
g = graph.traversal().withRemote(DriverRemoteConnection('wss://neptunedbcluster.neptune.amazonaws.com:8182/gremlin','g'))

g.V('p1').as_('this').out('ContributedTo').in_('ContributedTo').where(__.neq('this')).groupCount()

And I get an error:

AttributeError: type object '__' has no attribute 'neq'

How should I express Gremlin 'neq' in Python?

like image 437
ddegtyarev Avatar asked Jun 27 '26 04:06

ddegtyarev


1 Answers

neq is part of the P class, so I should import it and use it

from __future__  import print_function  # Python 2/3 compatibility

from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.traversal import P

from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection

graph = Graph()
g = graph.traversal().withRemote(DriverRemoteConnection('wss://neptunedbcluster.neptune.amazonaws.com:8182/gremlin','g'))

g.V('p1').as_('this').out('ContributedTo').in_('ContributedTo').where(P.neq('this')).groupCount()
like image 200
ddegtyarev Avatar answered Jun 29 '26 18:06

ddegtyarev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!