I have a dictionary object like the following
node_info = {'id':'2344','name':'xyz'}
I want to convert it to py2neo Node so that it can be created using graph.create()
. Node.cast()
is no longer supported. Any other way
I have a dictionary object like the following
node_info = {'id':'2344','name':'xyz'}
I want to convert it to py2neo Node so that it can be created using graph.create()
. Node.cast()
is no longer supported. Any other way
According to the definition for py2neo v4.0's Node class:
class py2neo.data.Node(*labels, **properties)
which means you can pass any number of labels:
Node("Person", "Professor")
and any number of labelled/named properties:
Node(id=10, name="Long John Silver")
You can achieve the above with either a list (for labels) and dict (for named properties):
labels = ["Person", "Professor"]
props = {"id": 10, "name": "Long John Silver"}
print(Node(*labels, **props))
will yield:
(:Person:Professor {id: 10, name: 'Long John Silver'})
This is because of Python's *args
and **kwargs
in python Geeks4Geeks ref