[英]How to convert a dictionary object to Node in py2neo?
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()
.我想将它转换为 py2neo Node,以便可以使用
graph.create()
创建它。 Node.cast()
is no longer supported.不再支持
Node.cast()
。 Any other way任何其他方式
According to the definition for py2neo v4.0's Node class :根据 py2neo v4.0 的Node 类的定义:
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这是因为 Python Geeks4Geeks ref 中的
*args
和**kwargs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.