pythonneo4jgraph-databasesneo4j-python-driver

Fetching results from cypher bolt statement


I am trying to access neo4j using neo4j python driver.I am running the following code to get a property of a thing A., I open the driver and session directly from GraphDatabase of neo4j and use session.run() to execute graph queries. These queries return a BoltStatementResult object.My question is how this object can be converted to actual result that I need(Property of thing A).?

    from neo4j import GraphDatabase

uri = "bolt://abc:7687"
driver = GraphDatabase.driver(uri, auth=("neo4j", "password"))

def matchQuestion(tx, intent,thing):

    result = tx.run("MATCH (e:thing) WHERE e.name = {thing}"
           "RETURN e.description", thing=thing)

    print(result)

with driver.session() as session:
    session.read_transaction(matchQuestion, "define","A")

Solution

  • result = tx.run("MATCH (e:thing) WHERE e.name = {thing}"
               "RETURN e.description AS description", thing=thing)
    
    for line in result:
        print line["description"]
    
    

    or

    print result.single()
    

    You could also specify the item position like -

    print result.single()[0]