TypeError: 'OrientRecord' object does not support indexing

TypeError: 'OrientRecord' object does not support indexing

我正在尝试使用 pyorient 从面向数据库中提取记录,这是我的查询:

query =  "SELECT value FROM (SELECT expand(Elements) FROM dataset) WHERE type = 'XXX'"
records = client.command(query)

一切正常。当我尝试打印记录时,这是我得到的:

record = records[0]
print type(record)
<class 'pyorient.otypes.OrientRecord'>


print record
{{'value': 'Name'},'version':0,'rid':'#-2:0'}

并且由于我只需要从 record 中提取“Name”,我尝试了:

print record[0]

得到了

TypeError: 'OrientRecord' object does not support indexing

这里是 repr 的结果:

print(repr(record))
<pyorient.otypes.OrientRecord object at 0x7fdcdb531ad0>

查看源代码后,我想出了如何从字符串表示中访问数据的各个部分:

>>> x
<pyorient.otypes.OrientRecord object at 0x105789e48>
>>> print(x)
{{'value': 'Name'},'version':0,'rid':'#-2:0'}
>>> x.oRecordData
{'value': 'Name'}
>>> x.value #allow for access in the oRecordData as attributes?
'Name'
>>> x._version, x._rid #other values in string representation
(0, '#-2:0')

令我非常失望的是,字符串表示形式并未使这一点变得明显。不管怎样,我想你想要 x.oRecordData 一个。