如何保存包含多个列表的for循环输出,这些列表是我在python中使用函数做出的API调用的各种响应?

发布于 2025-02-10 12:07:16 字数 400 浏览 2 评论 0原文

我正在使用API​​使用多个输入来收集数据。我使用for循环来通过我已经声明的输入值迭代来做出多个API请求。 API调用是使用用户定义的函数进行的。 这里响应_1是API调用的输入。

for auto_sort in response_1:
    countryname= auto_sort['Country']    
    iso=auto_sort['ThreeLetterSymbol']    
    response_3= api_call(countryname,iso)

我将功能输出作为单词列表,并在每次迭代中列出。

我想单独保存每个迭代输出,或将所有迭代(列表)组合到一个列表中。

需要帮助弄清楚如何完成或基本上如何处理在这种情况下的功能输出。我能够访问最新的迭代

I am using an api to collect data using multiple inputs. I used a for loop to make multiple api requests by iterating through the input values that i already declared . The api call was made using a user defined function.
Here response_1 is the inputs of the api call.

for auto_sort in response_1:
    countryname= auto_sort['Country']    
    iso=auto_sort['ThreeLetterSymbol']    
    response_3= api_call(countryname,iso)

I am getting the function output as a list of dictionary with each iteration.

I want to save each iteration output individually or combine all the iterations (lists) into one list.

Need help figuring out how this can be done or basically how can i handle the function output in this case. I am able to access the most recent iteration

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谜兔 2025-02-17 12:07:16

你快到了。只需使用列表,在每次迭代中,将API调用的响应附加到该列表中。

示例代码:


all_responses = []

for auto_sort in response_1:
    countryname= auto_sort['Country']    
    iso=auto_sort['ThreeLetterSymbol']    
    response_3= api_call(countryname,iso)

    all_responses.append(response_3)

You are almost there. Just use a list and in each iteration append the response of the api call to that list.

Example code:


all_responses = []

for auto_sort in response_1:
    countryname= auto_sort['Country']    
    iso=auto_sort['ThreeLetterSymbol']    
    response_3= api_call(countryname,iso)

    all_responses.append(response_3)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文