Python 如何为每个GerritInfo['GerritInfo']循环
我有下面的代码,我想在每个GerritInfo['GerritInfo'][0…n]上循环,并在此基础上添加逻辑,目前我只对第一项进行循环,即。, GerritInfo['GerritInfo'][0],假设我们不知道GerritInfo['GerritInfo']中有多少项,如何为每个GerritInfo['GerritInfo']循环Python 如何为每个GerritInfo['GerritInfo']循环,python,Python,我有下面的代码,我想在每个GerritInfo['GerritInfo'][0…n]上循环,并在此基础上添加逻辑,目前我只对第一项进行循环,即。, GerritInfo['GerritInfo'][0],假设我们不知道GerritInfo['GerritInfo']中有多少项,如何为每个GerritInfo['GerritInfo']循环 #!/usr/bin/python GerritInfo = {'Assignee': 'username', 'RCAInfo': 'Provided',
#!/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"
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"
如何在不添加for循环的情况下更改现有if循环