简体   繁体   中英

Using the py2neo driver, how can I create nodes from a list with the for loop?

I have successfully connected my neo4j database with the py2neo package. I am using jupyter notebook. I have a list that I need to create nodes with.

What do I put in $name part?

list = [a, b, c]
from py2neo import Database, Graph
db = Database("bolt://localhost:7687")
gr = Graph(password="password")

for name in list:
  gr.run("CREATE (:Person {name: $name})")

You can pass a name as a parameter to gr.run function.

for name in list:
  gr.run("CREATE (:Person {name: $name})", name=name)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM