In Python, I am trying to connect using Gremlin and execute a query.
Here I could connect to Neptune DB using gremlin and fetch vertices count using only print statement: print(g.V().has("system.tenantId", "hLWmgcH61m0bnaI9KpUj6z").count().next())
but while reading from a file and storing in a variable and passing in gremlin query is not working
Code
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()
remoteConn = DriverRemoteConnection('wss://<URL>:<port>/gremlin','g')
g = graph.traversal().withRemote(remoteConn)
with open ('Orgid1.txt','r') as file:
# orgstr = file.readlines()
# orgstr = [orgstr.rstrip() for line in orgstr]
for line in file:
print(g.V().has("system.tenantId", line.rstrip()).count().next())
# print(neptune)
#print(g.V().count())
#print(g.V().has("system.tenantId", "xyz123").count().next())
remoteConn.close()
Adding more details:
This is the code I am using:
input:
with open ('Orgid1.txt','r') as file:
for line in file:
print(g.V().has("system.tenantId", line.rstrip()).out().count().next())
output:
$ python3 gremlinexample.py
0
if I directly print it its working. input:
print(line.rstrip())
output:
$ python3 gremlinexample.py
0
xyz123
ps: xyz123 present in input file named as Orgid1.txt