如何检查graph_db.get_indexed_node的结果为空?

时间:2014-06-04 03:07:41

标签: neo4j nonetype py2neo

如何测试是否找到了NODE?

NODE = graph_db.get_indexed_node("index", "ID", "myID")
if (NODE == None):
    print "None found"
    exit()

不幸导致:

Traceback (most recent call last):
  File "foo.py", line 275, in foobar
    if (NODE == None):
  File "...\py2neo\neo4j.py", line 1499, in __eq__
    return _Entity.__eq__(self, other)
  File "...\py2neo\neo4j.py", line 324, in __eq__
    return self._resource == other._resource
AttributeError: 'NoneType' object has no attribute '_resource'

因为课程' py2neo.neo4j.Node'无法与"无"。

进行比较

如何检查graph_db.get_indexed_node的结果是否为空? 谢谢!

2 个答案:

答案 0 :(得分:0)

我找到了一个解决方法:

assert ( type(NODE) != type(None) )

yiehah! ; - )

答案 1 :(得分:0)

正确答案是使用:

if node is None:
    ...

assert Node is not None

与常量进行比较时,请始终使用is而不是==