抱歉,这个问题太愚蠢了,不能问...我是Python + Django + Bulbs + Neo4j的新手。

我正在尝试-但没有成功-使用g + greglin.execute()在使用Python + Django shell时产生一个整数,如下所述。

首先,在Neo4j的Gremlin控制台中查询:

gremlin> g.v(2).out
==> v[6]
==> v[4]
==> v[8]
==> v[7]
gremlin> g.v(2).out.count()
==> 4


我打算怎么做才能在Python + Django shell中获得此结果,并将其传递给变量,如下所示:

>>> from bulbs.neo4jserver import Graph
>>> from bulbs.model import Node,Relationship
>>> g = Graph()
>>> sc = " g.v(vertex_id).out.count()"
>>> params = dict(vertex_id = 2)
>>> val = g.gremlin.execute(sc,params)
>>> val
<bulbs.neo4jserver.client.Neo4jResponse object at 0x243cfd0>


从现在起我再也无法获得任何帮助。

>>> val.one()
<bulbs.neo4jserver.client.Neo4jResult object at 0x2446b90>
>>> val.one().data
>>> val.one().results
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'Neo4jResult' object has no attribute 'results'


谁能告诉我我在做什么错?
非常感谢!

最佳答案

原始结果数据将位于Result对象的raw属性中:

>>> from bulbs.neo4jserver import Graph
>>> from bulbs.model import Node,Relationship
>>> g = Graph()
>>> script = " g.v(vertex_id).out.count()"
>>> params = dict(vertex_id = 2)
>>> resp = g.gremlin.execute(script,params)
>>> result = resp.one()
>>> result.raw


注意:result.data返回元素的属性数据,因此除非您要返回顶点或边(即Neo4j的说法是节点或关系),否则它将为空。

看到...


https://github.com/espeed/bulbs/blob/master/bulbs/neo4jserver/client.py#L60
https://github.com/espeed/bulbs/blob/master/bulbs/neo4jserver/client.py#L88
https://github.com/espeed/bulbs/blob/master/bulbs/neo4jserver/client.py#L167


要查看服务器响应中返回的Neo4j Server,可以输出Response标头和内容:

>>> from bulbs.neo4jserver import Graph
>>> from bulbs.model import Node,Relationship
>>> g = Graph()
>>> script = "g.v(vertex_id).out.count()"
>>> params = dict(vertex_id = 2)
>>> resp = g.gremlin.execute(script,params)
>>> resp.headers
>>> resp.content


并且,如果您在DEBUG中将日志级别设置为Config,您将能够查看在每个请求中发送到服务器的内容。启用DEBUG时,灯泡还会在raw对象上设置Response属性(不要与总是在raw对象上设置的Result属性混淆)。 Response.raw将包含原始服务器响应:

>>> from bulbs.neo4jserver import Graph, DEBUG
>>> from bulbs.model import Node,Relationship
>>> g = Graph()
>>> g.config.set_logger(DEBUG)
>>> script = " g.v(vertex_id).out.count()"
>>> params = dict(vertex_id = 2)
>>> resp = g.gremlin.execute(script,params)
>>> resp.raw


看到...


https://github.com/espeed/bulbs/blob/master/bulbs/config.py#L70
https://github.com/espeed/bulbs/blob/master/bulbs/neo4jserver/client.py#L221
http://bulbflow.com/quickstart/#enable-debugging


要关闭DEBUG,请将日志级别设置回ERROR

>>> from bulbs.neo4jserver import ERROR
>>> g.config.set_logger(ERROR)


看到...


http://bulbflow.com/quickstart/#disable-debugging

关于python - Gremlin/Bulbflow:如何从execute()中获取整数结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18689133/

10-12 15:01