我正在尝试在列表中创建列表

时间:2019-07-31 19:50:50

标签: python loops for-loop

我试图遍历我所有的jira搜索并将它们包含在列表列表中

g_list= []
t_list= []
x=0

issues_in_project = jira.search_issues('labels=Reporting', expand='changelog', maxResults=False)

changelog = issue.changelog

for history in changelog.histories:
    for item in history.items:
        if item.field == 'status':
            t_list.append('Date:' + history.created + ' From:' + item.fromString + ' To:' + item.toString)
    g_list.append(t_list[0])

我想要的是将一个特定问题的所有状态更新作为一个元素包含在一个列表中。像

[[Date:2019-03-27T10:08:45.997-0400 From:Open To:In Progress,
Date:2019-04-02T12:33:46.356-0400 From:In Progress To:Closed],
[Date:2019-03-27T10:08:45.997-0400 From:Open To:In Progress],
[Date:2019-03-27T10:08:45.997-0400 From:Open To:In Progress]]

当前它给我一个错误:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-82-42338ca03d78> in <module>
     11         if item.field == 'status':
     12             t_list.append('Date:' + history.created + ' From:' + item.fromString + ' To:' + item.toString)
---> 13     g_list.append(t_list[0])

IndexError: list index out of range

仅运行changelog时-输出如下所示。

代码

for issue in issues_in_project:
    changelog = issue.changelog

for history in changelog.histories:
    for item in history.items:
        if item.field == 'status':
            print ('Date:' + history.created + ' From:' + item.fromString + ' To:' + item.toString)

解决方案

Date:2019-03-27T10:08:45.997-0400 From:Open To:In Progress
Date:2019-04-02T12:33:46.356-0400 From:In Progress To:Closed

1 个答案:

答案 0 :(得分:2)

看来t_list为空。您确定有一个名为“状态”的item.field吗?