Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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 2.7中的参数_Python_Loops_Python 2.7_Dynamic_Parameter Passing - Fatal编程技术网

循环以更改Python 2.7中的参数

循环以更改Python 2.7中的参数,python,loops,python-2.7,dynamic,parameter-passing,Python,Loops,Python 2.7,Dynamic,Parameter Passing,我有一段代码,它正在Excel中创建一个输出。 我现在要做的是让有效负载中的参数(lid)在其他ID的列表中循环 此列表存储在txt文件中 有人能修改我的代码来告诉我怎么做吗? 文本文件中有值 1654, 3457, 4327, 1234 (如果更容易,也可以在脚本中的某个位置硬编码) 为什么不将所有lid值作为参数传递给retrieve_data函数呢 def retrieve_data(api_url): 将成为 def retrieve_data(api_url, lid_value):

我有一段代码,它正在Excel中创建一个输出。 我现在要做的是让有效负载中的参数(lid)在其他ID的列表中循环

此列表存储在txt文件中

有人能修改我的代码来告诉我怎么做吗? 文本文件中有值 1654, 3457, 4327, 1234

(如果更容易,也可以在脚本中的某个位置硬编码)


为什么不将所有lid值作为参数传递给retrieve_data函数呢

def retrieve_data(api_url):
将成为

def retrieve_data(api_url, lid_value):
您将移除有效负载的硬编码
部分,使有效负载看起来像这样

payload = {'start': '2014-08-01T00:00:01', 'stop': '2014-  8-01T23:59:59','category': 'ots'}
然后在下一行,您可以添加

payload['lid'] = lid_value
在main函数中,可以循环遍历文本文件中的值。下面是一个带有列表的简单循环

def main():
    lid_values = ['1654', '3457', '4327', '1234']
    for lid in lid_values:
        retrieve_data(FULL_URL, lid)
    sys.exit()
def main():
    lid_values = ['1654', '3457', '4327', '1234']
    for lid in lid_values:
        retrieve_data(FULL_URL, lid)
    sys.exit()