简体   繁体   English

使用py2neo时如何在Cypher语句中使用Python变量

[英]How to use Python variables in a Cypher statement when using py2neo

I want to get some path by using py2neo but I didn't find the right way, so I choose to use graph.run(), when I run the statements below:我想通过使用 py2neo 获得一些路径,但我没有找到正确的方法,所以我选择使用 graph.run(),当我运行以下语句时:

t='T1018'
path1=graph.run("MATCH path=(m:attack{name:t})-[:next*1..2]->(n:attack) return path").to_series()

It will show error like this:它会显示这样的错误:

py2neo.errors.ClientError: [Statement.SyntaxError] Variable `t` not defined (line 1, column 27 (offset: 26))
"MATCH path=(m:attack{name:t})-[:next*1..2]->(n:attack) return path"

So how can I use the python variables in a cypher statement?那么如何在 cypher 语句中使用 python 变量呢? Or is there a way to get paths using py2neo statements?或者有没有办法使用 py2neo 语句获取路径? ^ ^

pass the arguments like as follows:像下面这样传递 arguments:

t='T1018'
path1=graph.run("""MATCH path=(m:attack{name:$x})-[:next*1..2]->(n:attack) return path""",x=t).to_series()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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