Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Graph py2neo:如何迭代所有使用开始节点和结束节点的关系?_Graph_Neo4j_Py2neo - Fatal编程技术网

Graph py2neo:如何迭代所有使用开始节点和结束节点的关系?

Graph py2neo:如何迭代所有使用开始节点和结束节点的关系?,graph,neo4j,py2neo,Graph,Neo4j,Py2neo,如何以开始节点和结束节点迭代图上的所有关系?。我试过: import sys import time import json from py2neo import Graph, Node, authenticate, Relationship graph =Graph() cypher = graph.cypher def handle_row(row): a,b = row ... do some stuff with a,b cypher.execute("match (

如何以开始节点和结束节点迭代图上的所有关系?。我试过:

import sys
import time
import json
from py2neo import Graph, Node, authenticate, Relationship
graph =Graph()
cypher = graph.cypher

def handle_row(row):
    a,b = row
    ... do some stuff with a,b

cypher.execute("match (a)-[]->(b) return a, b", row_handler=handle_row)
但我得到了一个错误:

`typeError: <function handle_row at ...> is not JSON serializable`
`typeError:不可序列化JSON`
函数的
cypher.execute()
不将结果处理程序作为参数。它将查询参数作为字典或关键字参数。这些参数然后作为JSON发送到neo4j。您的
handle\u row
函数不可JSON序列化,因此出现
TypeError

要对所有节点执行某些操作,请尝试以下操作:

result = graph.cypher.execute('MATCH (a)-[]->(b) RETURN a, b')
for row in result:
    print(row)
    print(row[0])
    print(row[2])

请参阅此处的示例:

我也可以在文档中使用:
用于graph.cypher.stream中的r(“匹配(a)-[]->(b)返回id(a),id(b)”:打印(r[0],r[1])
。你知道在效率方面的区别吗?我想说,对于大的结果集,流更好。