0

my list looks like:

lst
['78251'],
 ['18261'],
 ['435921'],
 ['74252'],
 ...]

I want to place that numbers into a url code http://api.brain-map.org/api/v2/data/query.xml?criteria=model::SectionDataSet,rma::criteria,[failed$eq%27false%27],products[abbreviation$eq%27Mouse%27],genes[entrez_id$eq%27inhere%27]'

I tried

for i in lst:
    b = 'http://api.brain-map.org/api/v2/data/query.xml?criteria=model::SectionDataSet,rma::criteria,[failed$eq%27false%27],products[abbreviation$eq%27Mouse%27],genes[entrez_id$eq%27%d%27]' %i

I get no error message but it says


b
Traceback (most recent call last):

  File "<ipython-input-79-89e6c98d9288>", line 1, in <module>
    b

NameError: name 'b' is not defined

So I think the difficult part is that there is no space in between the string... How can I handle this?

2
  • The error is caused by a b in your code. There is no b variable in what you've included. It seems you've entered a b and pressed enter from your error message. Commented May 4, 2020 at 11:17
  • Oh sorry I changed the code.. I tried to safe the url in b Commented May 4, 2020 at 11:20

3 Answers 3

1

The URL is complex, but see example URL:

a= 'http://api.brain-map.org/api/v2/data/query.xml?criteria=' + i + '&gene=model:' + i
Sign up to request clarification or add additional context in comments.

1 Comment

Oh I tried this but I forgot a second +.. thank you!
1

Try this much more pythonic approach, using .format():

for i in lst:
    b = "http://api.brain-map.org/api/v2/data/query.xml?criteria=model::SectionDataSet,rma::criteria,[failed$eq%27false%27],products[abbreviation$eq%27Mouse%27],genes[entrez_id$eq%27{}%27]".format(i[0])

Comments

0
lst = [["78251"], ["18261"], ["435921"], ["74252"]]
for val, in lst:
    b = "http://api.brain-map.org/api/v2/data/query.xml?criteria=model::SectionDataSet," \
        "rma::criteria,[failed$eq%27false%27],products[abbreviation$eq%27Mouse%27]," \
        f"genes[entrez_id$eq%27{val}%27]"

Directly access to values of interest with val, in lst and use implicit string concatenation along with an f-string at the end to substitute the value.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.