AttributeError: 'Graph' object has no attribute 'cypher' :新版本执行语句不一样
python 3.6.6 neo4j:3.5.9 参考https://py2neo.org/2021.1/
(flask_py) E:\githubwks\cytoscape_neo4j>pip install py2neo
(flask_py) E:\githubwks\cytoscape_neo4j>python
Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from py2neo import Graph
>>> graph = Graph("bolt://localhost:7687", auth=("root", "root"))
>>> graph.run("UNWIND range(1, 3) AS n RETURN n, n * n as n_sq")
-1 -1
n | n_sq
---|------
1 | 1
2 | 4
3 | 9
>>> graph.cypher.execute('MATCH (n) RETURN n')
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'Graph' object has no attribute 'cypher'
>>> graph.run('MATCH (n) RETURN n')
-1 -1
n
--------------------------------------------------------------------------------------------------------------
(_132208:ProductEntry {introduction: 'GOOD', name: 'telephone', productEntryId: 'huwei1004'})
(_132228:CompanyEntry {companyid: 66, name: '66', type: '66', uuid: '270e142d-929e-434f-a5c1-38a7796b3a34'})
(_132229:CompanyEntry {companyid: 1961, name: 'Laurence Fishburne', type: 'A'})
>>> result = graph.run('MATCH (n:CompanyEntry) RETURN n').data()
-1 -1
>>> result
[{'n': Node('CompanyEntry', companyid=66, name='66', type='66', uuid='270e142d-929e-434f-a5c1-38a7796b3a34')}, {'n': Node('CompanyEntry', companyid=1961, name='Laurence Fishburne', type='A')}]
>>> result[0]
{'n': Node('CompanyEntry', companyid=66, name='66', type='66', uuid='270e142d-929e-434f-a5c1-38a7796b3a34')}
>>> result[0].n.name
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'dict' object has no attribute 'n'
>>> result[0]
{'n': Node('CompanyEntry', companyid=66, name='66', type='66', uuid='270e142d-929e-434f-a5c1-38a7796b3a34')}
>>> result[0].get('n')
Node('CompanyEntry', companyid=66, name='66', type='66', uuid='270e142d-929e-434f-a5c1-38a7796b3a34')
>>> result[0].get('n').get('name')
'66'
我们执行完返回是cursor,evaluate执行后移动游标了。
>>> cursor = graph.run('MATCH (n:CompanyEntry) RETURN n')
-1 -1
>>> cursor.evaluate()
Node('CompanyEntry', companyid=66, name='66', type='66', uuid='270e142d-929e-434f-a5c1-38a7796b3a34')
>>> cursor.evaluate()
Node('CompanyEntry', companyid=1961, name='Laurence Fishburne', type='A')
>>> cursor.evaluate()
>>>
>>> cursor = graph.run('MATCH (n:CompanyEntry)-[p]->(m) RETURN n,p,m').data()
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
>>> cursor
[{'n': Node('CompanyEntry', companyid=1961, name='Laurence Fishburne', type='A'), 'p': Production(Node('CompanyEntry', companyid=1961, name='Laurence Fishburne', type='A'), Node('ProductEntry', introduction='GOOD', name='telephone', productEntryId='huwei1004'), capacity='10V', uuid='182e7682-52c4-4fe5-95cd-841726bbfbba'), 'm': Node('ProductEntry', introduction='GOOD', name='telephone', productEntryId='huwei1004')}]
>>> cursor = graph.run('MATCH (n:CompanyEntry)-[p]->(m) RETURN n,p,m')
-1 -1
>>> cursor.data()
-1 -1
-1 -1
-1 -1
-1 -1
[{'n': Node('CompanyEntry', companyid=1961, name='Laurence Fishburne', type='A'), 'p': Production(Node('CompanyEntry', companyid=1961, name='Laurence Fishburne', type='A'), Node('ProductEntry', introduction='GOOD', name='telephone', productEntryId='huwei1004'), capacity='10V', uuid='182e7682-52c4-4fe5-95cd-841726bbfbba'), 'm': Node('ProductEntry', introduction='GOOD', name='telephone', productEntryId='huwei1004')}]
>>> cursor[0]
Node('CompanyEntry', companyid=1961, name='Laurence Fishburne', type='A')
>>> cursor[1]
Production(Node('CompanyEntry', companyid=1961, name='Laurence Fishburne', type='A'), Node('ProductEntry', introduction='GOOD', name='telephone', productEntryId='huwei1004'), capacity='10V', uuid='182e7682-52c4-4fe5-95cd-841726bbfbba')
>>> cursor[2]
Node('ProductEntry', introduction='GOOD', name='telephone', productEntryId='huwei1004')