通过功能python中的结肠传递变量



我正在使用此API ..其功能调用看起来像:

g.vertices.index.lookup(identifier="value")

现在请注意,idenitifier是一个变量,我尚未定义,但由API固定,值是字符串。

Pymongo API中发生了类似的事情:http://api.mongodb.org/python/current/tutorial.html

db = client.test_database

等于

db = client["test_database"]

test_database在第一种情况下,即使用户尚未定义该变量..但Mongo可以理解,在我的数据存储中,我是否有一个称为test_database的数据库。

现在,我的问题是:我的数据存储器中有一个结肠。

那就是:

g.vertices.index.lookup(bad:identifier="value")

参见..查询中的结肠..

,此API没有蒙戈型字典实现。

我知道,我应该解决这个问题的原因。

问题是因为那个结肠,我得到了

g.vertices.index.lookup(bad:identifier="value")
                           ^
SyntaxError: invalid syntax

我如何解决此

g.vertices.index.lookup(**{"bad:identifier":"value"})

可能有效...这被称为解开关键字参数

在灯泡中,index.lookup(key = value)只是index.lookup(key,value)的句法糖,因此您可以简单地执行此操作:

>>> g.vertices.index.lookup("bad:identifier", "value")

您没有说明您正在使用的哪个图形数据库服务器(Neo4J服务器,Rexster或Titan),但每个语法都相同。看到...

  • https://github.com/espeed/bulbs/blob/master/bulbs/rexster/rexster/index.py#l266
  • http://bulbflow.com/docs/api/bulbs/rexster/indices/

最新更新