cancel
Showing results for 
Search instead for 
Did you mean: 

Python script to Neo4j - NameError: name 'session' is not defined

stephflint
Node Clone

Hi,

I'm getting the following error when trying to run a python script that is connected to my graph:

Traceback (most recent call last):
  File "/Users/Python scripts/python/cdpipe.py", line 46, in <module>
    result = session.run(query)
NameError: name 'session' is not defined

 Here is my code snippet where the error occurs:

query = "MATCH (d:Document) WHERE size((a)-[:HAS_WORD]->(:Word)) = 0 RETURN a.company as company, a.doctype as doctype, a.text as text"
result = session.run(query)

baselist = []
for record in result:   
	baselist.append(record);
	
for rec in baselist:
	company = rec["company"]
	ndocument = rec["doctype"]
	ntext = rec["text"]
	print("processing company %s doctype %s" % (company, ndoctype))
	parameters = { "companyv": company, "wordsv": getWords(ndoctype, stopwords, ps) };

Anyone know why this happens? I ran a very similar script a few minutes ago and it worked - but I'm stumped on this.

Any help very much appreciated

 

2 REPLIES 2

Share your full script. You're probably not creating the session in the right place.

 

see https://neo4j.com/developer/python/

stephflint
Node Clone

Hi @michael_hunger - thank you - I actually realised the error - and it was, as you mentioned not creating the session correctly. Case closed !