TypeError:“OrientRecord”对象不支持索引

2024-05-05 08:36:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用pyorient从定向数据库中提取记录,下面是我的查询:

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

一切都很好。当我试图打印记录时,我得到的是:

^{pr2}$

因为我只需要从record中提取Name,所以我尝试了:

print record[0]

得到了

TypeError: 'OrientRecord' object does not support indexing

这是repr的结果:

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

Tags: from数据库objectvalue记录elementsrecordquery
1条回答
网友
1楼 · 发布于 2024-05-05 08:36:26

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

>>> 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的。在

相关问题 更多 >