2

I am running Gremlin-Pyton in a Jupyter notebook and for some reason the following does not work:

g.V().group().by().by(bothE().count())

I keep getting the error:

NameError: name 'bothE' is not defined
0

1 Answer 1

1

If you followed the typical imports listed in the documentation:

>>> 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

then bothE is available as __.bothE.

The methods in the __ namespace can be added to your notebook globals with:

>>> statics.load_statics(globals())

so you can access bothE directly without a prefix.

Quoting from the documentation:

Moreover, by importing the statics of Gremlin-Python, the class prefixes can be omitted.

>>> statics.load_statics(globals())

and

Finally, statics includes all the -methods and thus, anonymous traversals like .out() can be expressed as below. That is, without the __.-prefix.

>>> g.V().repeat(out()).times(2).name.fold().toList()
[[ripple, lop]]

Caveat: I am not a Gremlin-Python user nor is it practical for me to install Gremlin to verify the above completely. I based this on reading the documentation and a scan of the project source code.

Sign up to request clarification or add additional context in comments.

6 Comments

thank you where do i run the "statics.load_statics(globals())", when i run it in my jupyter notebook it does not work nor in my gremlin console
@Maths12: 'does not work' is not really something I can work with. What happens instead? It's Python code, run it in your notebook like you ran the from gremlin_python import ... statements, without the >>> prefix.
NameError: name 'statics' is not defined <-- this is the error. and i have imported all the imports listed in documentation.
The name error suggests you are missing from gremlin_python import statics. The statics.load_statics(globals()) line can only run after you imported statics.
thanks, i did do that import for some reason it wasn;t being recognised. I have imported a different way and it works now
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.