Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing a variable with colon in function python

Tags:

python

bulbs

I am using this api.. whose function call looks like:

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

Now note that idenitifier is a variable which I have not defined but is resoluted by api and value is a string.

Something similar happens in pymongo api: http://api.mongodb.org/python/current/tutorial.html

db = client.test_database

is equal to

db = client["test_database"]

test_database in first case, even though user hasnt defined that variable.. but is understood by mongo that in my datastore, do i have a database called test_database or not..

Now, the issue I have is this: I have a colon in my datastore..

Which is to say it is like:

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

See.. the colon in the query..

And this api doesnt have that mongo type dictionary implementation..

I know, I should resolve this as in why I am getting this colon.. but this is what I am stuck at right now..

And the issue is because of that colon, I get

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

How do i resolve this

like image 223
frazman Avatar asked Dec 25 '22 14:12

frazman


2 Answers

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

may work ... this is known as unpacking keyword arguments

like image 130
Joran Beasley Avatar answered Jan 04 '23 18:01

Joran Beasley


In Bulbs, index.lookup(key=value) is just syntactic sugar for index.lookup(key, value) so you could simply do this:

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

You didn't indicate which graph database server you are using (Neo4j Server, Rexster, or Titan), but the syntax is the same for each. See...

  • https://github.com/espeed/bulbs/blob/master/bulbs/rexster/index.py#L266
  • http://bulbflow.com/docs/api/bulbs/rexster/indices/
like image 22
espeed Avatar answered Jan 04 '23 18:01

espeed