从jira attachment python获取附件ID

时间:2014-12-26 14:16:52

标签: python list python-jira

我可以使用python使用issue.fields.attachment

显示jira中的附件
attach_list = issue.fields.attachment
print attach_list
print attach_list[0]
print attach_list[1]

输出

  [<JIRA Attachment: filename=u'test.xlsx', 
     id=u'525427', 
     mimeType=u'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'>,
   <JIRA Attachment: filename=u'test2.csv', 
     id=u'525515', 
     mimeType=u'application/vnd.ms-excel'> ]

    test.xlsx
    test2.csv

如何从该列表中检索ID。在上面的例子中,我需要检索525427

请建议我?

1 个答案:

答案 0 :(得分:3)

只需访问id属性:

attach_list[0].id

如果您需要id列表,请使用list comprehension

attach_list = issue.fields.attachment
id_list = [attach.id for attach in attach_list]