【发布时间】:2015-06-24 16:09:02
【问题描述】:
我正在使用
处理 Cypher 语句result = my_cypher.my_transaction.process()
我的问题是我不知道如何优雅地得到结果。我偶然发现 process() 返回一个 RecordListList 但我不知道如何处理它,除了迭代它。这让我很恼火,因为在我的这部分代码中,我一次处理一个语句,并不需要迭代任何东西。 (不过,我仍然在单笔交易中。)
这就是我现在这样做的原因,它正在燃烧我的灵魂:
result = cypher.tx.process()
for r in result:
for x in r:
node_id = x['node_id']
但是r 和x 将永远只有一行。如果我能直接得到结果,我会更开心:
node_id = result.one().one()['node_id']
编辑 1
我使用 ipython 来显示 process() 上可用的方法列表。其中之一是pop()。现在我有这个可憎的:
result = cypher.process()
one_row = result.pop()
tmp = one_row[0]['node_id']
更好,但仍然丑陋。
编辑 2
显然,RecordList 中有一个魔法可以从所述记录集中提取第一行。这是一个名为one 的属性。很奇怪,它不是一种方法。
result = cypher.process()
one_row = result.pop()
node_id = one_row.one['node_id']
【问题讨论】: