Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将列表外的变量放入字符串(url代码)_Python_String - Fatal编程技术网

Python 将列表外的变量放入字符串(url代码)

Python 将列表外的变量放入字符串(url代码),python,string,Python,String,我的清单如下: lst ['78251'], ['18261'], ['435921'], ['74252'], ...] 我想把这些数字放到一个url代码中 $eq%27false%27],产品[缩写$eq%27Mouse%27],基因[entrez_id$eq%27固有的%27]' 我试过了 for i in lst: b = 'http://api.brain-map.org/api/v2/data/query.xml?criteria=model::SectionDat

我的清单如下:

lst
['78251'],
 ['18261'],
 ['435921'],
 ['74252'],
 ...]
我想把这些数字放到一个url代码中 $eq%27false%27],产品[缩写$eq%27Mouse%27],基因[entrez_id$eq%27固有的%27]'

我试过了

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
我没有收到错误消息,但它说


b
Traceback (most recent call last):

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

NameError: name 'b' is not defined

B
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
B
名称错误:未定义名称“b”

所以我认为最困难的部分是在弦之间没有空间。。。如何处理此问题?

URL很复杂,但请参见示例URL:

a= 'http://api.brain-map.org/api/v2/data/query.xml?criteria=' + i + '&gene=model:' + i

URL很复杂,但请参见示例URL:

a= 'http://api.brain-map.org/api/v2/data/query.xml?criteria=' + i + '&gene=model:' + i

使用.format()尝试这种更具python风格的方法:


使用.format()尝试这种更具python风格的方法:

在lst中,使用
val直接访问感兴趣的值,并使用隐式字符串连接以及末尾的f字符串替换该值


使用lst中的
val直接访问感兴趣的值,并使用隐式字符串连接以及末尾的f字符串替换值。

错误是由代码中的
b
引起的。您包含的内容中没有
b
变量。您似乎输入了a
b
并从错误消息中按了enter键。哦,对不起,我更改了代码。。我试图在b中保护url。错误是由代码中的a
b
引起的。您包含的内容中没有
b
变量。您似乎输入了a
b
并从错误消息中按了enter键。哦,对不起,我更改了代码。。我试图安全的网址在后台我尝试了这个,但我忘记了第二+。。非常感谢。哦,我试过了,但我忘记了第二个+。。非常感谢。
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]"