如何测试是否找到了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的结果是否为空? 谢谢!
答案 0 :(得分:0)
我找到了一个解决方法:
assert ( type(NODE) != type(None) )
yiehah! ; - )
答案 1 :(得分:0)
正确答案是使用:
if node is None:
...
或
assert Node is not None
与常量进行比较时,请始终使用is
而不是==
。