Reputation: 11
I am using the requests module in python to construct URLs for API queries. Following is the code that I am using:
Params = {'q':'3145','organism':'9606'}
results = requests.get("http://www.pathwaycommons.org/pc2/search.xml",params=Params)
print results.url #http://www.pathwaycommons.org/pc2/search.xml?q=3146&organism=9606
I want to add an OR condition to the q parameter (q = 3145 or 177). The ultimate url would be http://www.pathwaycommons.org/pc2/search.xml?q=3146|177&organism=9606
. If I used Params = {'q':['3145','177'],'organism':'9606'}
, the output url is "http://www.pathwaycommons.org/pc2/search.xml?q=3146&q=177&organism=9606"
. I have not found any information about how to define a parameter dictionary for an OR condition. Could anybody give some idea?
Thank you in advance.
Wendy
Upvotes: 1
Views: 1410
Reputation: 298196
This is the first time I've seen this "OR" syntax, so I'm not sure if it's standard.
Anyways, you could just join
the parameter list to create a string, like so:
params = {
'q': '|'.join(['3145','177']),
'organism': '9606'
}
Upvotes: 5