节点已添加到 neo4j DB 但打印为 "None"

Node added to neo4j DB but prints out as "None"

我有以下代码:

import py2neo
from py2neo import Graph, Node, Relationship

def createRelationshipWithProperties():
    print("Start - Creating Relationships")
    # Authenticate the user using py2neo.authentication
    # Ensure that you change the password 'sumit' as per your database configuration.
    py2neo.authenticate("localhost:7474", "neo4j", "")
    # Connect to Graph and get the instance of Graph
    graph = Graph("http://localhost:7474/db/data/")
    # Create Node with Properties
    amy = Node("FEMALE", name="Amy")
    # Create one more Node with Properties
    kristine = Node("FEMALE",name="Kristine")
    # Create one more Node with Properties
    sheryl = Node("FEMALE",name="Sheryl")

    kristine_amy = Relationship(kristine,"FRIEND",amy,since=2005)
    print (kristine_amy)
    amy_sheryl = Relationship(sheryl,("FRIEND"),amy,since=2001)

    #Finally use graph Object and Create Nodes and Relationship
    #When we create Relationship between, then Nodes are also created. 
    resultNodes = graph.create(kristine_amy)
    resultNodes1 = graph.create(amy_sheryl)
    #Print the results (relationships)
    print("Relationship Created - ",resultNodes)
    print("Relationship Created - ",resultNodes1)

if __name__ == '__main__':
    createRelationshipWithProperties()

resultsNodes = graph.create 行似乎将节点和关系提交给服务器,因为我在 match(n) Return n 时可以看到它们。但是,当代码打印 resultsNodes 时,我得到 None 就好像它们不存在一样。这是我得到的输出:

Start - Creating Relationships
(kristine)-[:FRIEND {since:2005}]->(amy)
Relationship Created -  None
Relationship Created -  None

您使用的 API 不正确。 create 方法没有 return 节点,而是更新提供的参数。因此要获取关系节点,您需要在执行创建后查询关系对象。