【问题标题】:Python read from API and write to an array/listPython 从 API 读取并写入数组/列表
【发布时间】:2020-09-25 19:14:24
【问题描述】:

我能够从 API 读取并写入列表,但格式如下: ('AAA','FF','LL') ('BBB','SS','DD')

如何迭代嵌套以分别从第一行获取信息为 AAA、FF、LL。

谢谢。 阿杰

【问题讨论】:

    标签: python arrays api


    【解决方案1】:

    Python - Parsing JSON formatted text file with regex

    此答案将帮助您处理输入数据。我建议使用以下代码结构。我会提供一些伪代码:

    list1
    for item in APIInput:
        //Find each element in item by dividing the string on commas, remove ( and '
        //take each element and put it into another list (list2)
        //Add that list (list2) to list1
    
    

    RegEx 对于这类工作来说非常强大。

    【讨论】:

    • 试试这个:for item in YourList: print item
    • 我得到的输出为 ('AAA','FF',LL)
    • 您是否将 API 返回的每个元素都放入一个列表中?或者你正在做这样的事情? variable = APIList[1] 我建议使用 RegEx 来解析您的输入
    • 打印项目输出为 ('apple', 'Fruit','red') ('orange', 'Fruit','orange') ('Cucumber', 'Veggie', 'green ')
    • 从 API 获取响应数据。数据 = response.json()
    猜你喜欢
    • 1970-01-01
    • 2020-10-06
    • 2021-04-28
    • 2016-03-20
    • 2013-04-24
    • 2016-07-12
    • 2020-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多