我怎样才能为每个GerritInfo循环[' GerritInfo']

时间:2014-06-03 23:24:19

标签: python

我有以下代码,我想遍历每个GerritInfo [' GerritInfo'] [0 ... n]并根据它添加逻辑,目前我只对第一个项目进行操作,即, GerritInfo [' GerritInfo'] [0],如果我们不知道GerritInfo中有多少项,那么如何循环每个GerritInfo [' GerritInfo'] [' GerritInfo' ]

#!/usr/bin/python
GerritInfo = {'Assignee': 'username', 'RCAInfo': 'Provided', 'PLProductLine': 'LNX.LA.0.0', 'GerritInfo': [{'Url': 'https://review-android.company.com/761190', 'Status': 'MERGED', 'kw_ran': 'kw running', 'Info': 'ALREADY INTEGRATED', 'lookahead_ran': 'lookahead running'}, {'Url': 'https://review-android.company.com/777849', 'Status': 'NEW', 'kw_ran': 'kw did not run', 'Info': 'Available', 'lookahead_ran': 'lookahead running'}], 'CRId': '<a href="http://prism/CR/664310">664310</a>', 'CRStatus': 'Fix', 'RNotesStatus': 'Yes', 'TargetName': 'MSM8916', 'IsDevComplete': 'True'}


if (('Not Provided' in GerritInfo['GerritInfo'][0]['Url'] or 'Wrong Gerrit Provided' in GerritInfo['GerritInfo'][0]['Url']) or ('NEW' in GerritInfo['GerritInfo'][0]['Status'] or 'ABANDONED' in GerritInfo['GerritInfo'][0]['Status'] or 'Yes' not in GerritInfo['RNotesStatus'] or 'Provided' not in GerritInfo['RCAInfo'] or 'False' in str(GerritInfo['IsDevComplete']))):
    print "Inside if"
else:
    print "in else"

1 个答案:

答案 0 :(得分:0)

GerritInfo ['GerritInfo']中的数据只是一个列表,因此您可以使用正常的习惯用法循环它。

for gerrit in GerritInfo['GerritInfo']:
    print gerrit

编辑: 只需将现有逻辑包装在for循环中。例如

for gerrit in GerritInfo['GerritInfo']:
    if (('Not Provided' in gerrit['Url'] or 'Wrong Gerrit..))
        print "inside if"