Baraa
Baraa

Reputation: 11

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:

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? Or is there a way to get paths using py2neo statements? ^

Upvotes: 1

Views: 144

Answers (1)

micro5
micro5

Reputation: 415

pass the arguments like as follows:

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

Upvotes: 1

Related Questions