如何使用Grakn Python驱动程序检索所有变量
我想使用Grakn Python客户端获取查询中的所有变量。这是我的疑问:如何使用Grakn Python驱动程序检索所有变量,python,vaticle-typedb,vaticle-typeql,Python,Vaticle Typedb,Vaticle Typeql,我想使用Grakn Python客户端获取查询中的所有变量。这是我的疑问: match $p isa person; $f isa family; $r ($p, $f); get; 我使用文档中的以下代码: answer_iterator = read_transaction.query(read_query) for answer in answer_iterator: ans = answer.map().get("x") print("Retrieved ans
match $p isa person;
$f isa family;
$r ($p, $f);
get;
我使用文档中的以下代码:
answer_iterator = read_transaction.query(read_query)
for answer in answer_iterator:
ans = answer.map().get("x")
print("Retrieved ans with id " + ans.id)
但是,当我运行此命令时,会出现以下错误:
print("Retrieved ans with id " + ans.id)
AttributeError: 'NoneType' object has no attribute 'id
是否可以检索查询中的所有变量而不必逐个指定它们 是的,这是可能的,事实上你已经做到了
answer.map()
是一个python字典,变量名作为键(字符串),概念对象作为值。(文件)
因此,要打印所有概念的ID(使用Python 3.6+中的f字符串):
对于应答迭代器中的应答:
ans_dict=answer.map()
对于var,ans_dict.items()中的概念:
打印(f“检索到id为{concept.id}的变量{var}的ans”)