py2neo:如何迭代所有采用起始节点和结束节点的关系?

py2neo: How to iterate over all relationships taking the start node and the end node?

如何以起始节点和结束节点遍历图上的所有关系?。我试过:

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`

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

查看示例:http://py2neo.org/2.0/cypher.html#api-cypher