python - Py2neo - "set_node_property"的正确用法

标签 python py2neo

我正在尝试使用 py2neo 在索引列表中的特定节点上设置新属性。这个想法是列表中的第一个节点将获得一个新属性。该属性值将是静态的,以便将来找到所有相关的节点。在下面的示例中,“nodez”列表将发生变化,但第一项始终需要新的属性和静态值。

from py2neo import neo4j, cypher
graph_db = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")

nodez = ['test1', 'test2', 'test3']
mytestindex = graph_db.get_or_create_index(neo4j.Node, "name")
nodes2 = []
for word in nodez:
    nodes2.append(mytestindex.get_or_create("name", word, {"name": word}))
a = nodes2[0]
newpropkey = "new_property"
newpropvalue = "static_value"
set_node_property(a, newpropkey, newpropvalue)

因此,如果下次运行该程序且 nodez = ['test4', 'test5', 'test6'],则 'test1' 和 'test4' 都将包含新的属性值。例如,以下 cypher 查询将返回索引“name”中“test1”和“test4”的节点。感谢您的帮助!

START a = node:name(new_property="static_value")

最佳答案

set_node_property 仅适用于批量操作。在这种情况下,您只需使用:

a[newpropkey] = newpropvalue

关于python - Py2neo - "set_node_property"的正确用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14665274/

相关文章:

python - 使用 py2neo 将数据从 XML 加载到 neo4j

neo4j - 如何在 Py2neo v3 中将密码查询组合到事务中

python - 在 NeoModel 中创建之前查看节点是否存在

python - 我们什么时候在程序中添加错误处理代码?

python - 使用 curl 时让python发送回车键

Python 循环中的行为

python - django 和 virtualenv 的问题

python - Pandas Plot,如何控制条形宽度和间隙

python - Python py2neo SocketError : Connection Refused

merge - 理解 Py2neo 上的合并问题