如何在获取起始节点和结束节点的图形上迭代所有关系?我试过:
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`
答案 0 :(得分:3)
cypher.execute()
函数不将结果处理程序作为参数。它将查询参数作为字典或关键字参数。然后将这些参数作为JSON发送到neo4j。您的handle_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])