3

我正在尝试使用从定向数据库中提取记录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'}

并且由于我只需要从中提取 ' Name' record,因此我尝试了:

print record[0]

并得到

TypeError: 'OrientRecord' object does not support indexing

这是结果repr

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

1 回答 1

6

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

>>> 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

于 2016-04-12T04:06:05.360 回答