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])
。你知道在效率方面的区别吗?我想说,对于大的结果集,流更好。