列表的元素可以用于图节点的属性吗?

2024-09-30 01:36:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我还不熟悉使用Neo4j和Python。我想知道在Python和Neo4j中是否可以使用列表元素作为图节点的属性

我试图创建一个配方节点,但在“createNode”变量中出现错误。我做错什么了

这是我的密码:

# a list containing a list of recipes and their respective information 
recipeList = [['Mac and Cheese', 'Anytime', 'Macaroni', 'Terry'], ['Chicken Curry', 'Supper', 'Chicken', 'Anne']]

def print_recipes(self,aList):
    with self._driver.session() as session:
       recipes = session.write_transaction(self.createRecipeNodes,aList)
            print(recipes)


def createRecipeNodes(tx, aRecipeList):

    for allRecipes in aRecipeList:
        #for recipe in allRecipes:
        recipeName = allRecipes[0]
        serveTime = allRecipes[1]
        mainIngrediant = allRecipes[2]
        givenBy =  allRecipes[3]

        createNode = tx.run("CREATE (theNode:Recipe {recipeName = {recipeName}, serveTime = {serveTime}, mainIngrediant = {mainIngrediant}, givenBy = {givenBy}" ,recipeName=recipeName,serveTime=serveTime,mainIngrediant=mainIngrediant,givenBy=givenBy)

我得到的错误是:

neo4j.exceptions.CypherSyntaxError: Invalid input '=': expected whitespace, comment, ':' or '}' (line 1, column 36 (offset: 35)) "CREATE (theNode:Recipe {recipeName = {recipeName}, serveTime = {serveTime}, mainIngrediant = {mainIngrediant}, givenBy = {givenBy}

提前谢谢


Tags: andself节点session错误listneo4jrecipes
1条回答
网友
1楼 · 发布于 2024-09-30 01:36:25

Cypher查询不使用=进行属性赋值,而是使用:

createNode = tx.run("CREATE (theNode:Recipe {recipeName: {recipeName}, serveTime: {serveTime}, mainIngrediant: {mainIngrediant}, givenBy: {givenBy}"
 ,recipeName=recipeName,serveTime=serveTime,mainIngrediant=mainIngrediant,givenBy=givenBy)

相关问题 更多 >

    热门问题