[英]How to convert a dictionary object to Node in py2neo?
我有一個像下面這樣的字典對象
node_info = {'id':'2344','name':'xyz'}
我想將它轉換為 py2neo Node,以便可以使用graph.create()
創建它。 不再支持Node.cast()
。 任何其他方式
根據 py2neo v4.0 的Node 類的定義:
class py2neo.data.Node(*labels, **properties)
這意味着您可以傳遞任意數量的標簽:
Node("Person", "Professor")
以及任意數量的標記/命名屬性:
Node(id=10, name="Long John Silver")
您可以使用列表(用於標簽)和字典(用於命名屬性)來實現上述目的:
labels = ["Person", "Professor"]
props = {"id": 10, "name": "Long John Silver"}
print(Node(*labels, **props))
將產生:
(:Person:Professor {id: 10, name: 'Long John Silver'})
這是因為 Python Geeks4Geeks ref 中的*args
和**kwargs
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.