#Can be more than two items also.
item_list = ["rpm", "exe"]
extraction_status = True
while extraction_status:
file_status_flag = True
file_status = some_other_function(arg1, arg2) # returns a nested dictionary of lists.
for item in file_status['BU']: # file_status['BU'] = ["HR", "DEV" ,"Admin"]
if item['extensions'] in item_list: #rpm or exe or zip
if (file_status['status'] == "PUSHED")):
print("file from {} reached target..".format(item))
#do further action on that file
continue # not working
else:
print("Status of {} is {}".format(item, file_status['status']))
# To check if all the items in item_list has been pushed.
if (file_status_flag and (file_status['status'] == "PUSHED")):
"All files reached target..make the script successful.."
extraction_status = False
让我解释一下,如果HR在第一次或迭代中处于PUSHED状态,则从后续迭代开始执行某些操作,如果满足条件则跳过。continue
跳过了当前的迭代,这不是我想要的。
这可能吗?
示例输出
1st iteration:
file from BU reached target
file from DEV In Progress
file from Admin Not Prepared
2nd iteration:
file from DEV In Progress
file from Admin In Progress
所以..
2条答案
按热度按时间q8l4jmvw1#
为什么不添加另一个标志来查看你是否已经检查了条件?例如,我们可以添加一个名为
already_checked
的标志,在第一次迭代时将其设置为True
,然后,如果它已经是True
,则跳过进一步的操作:8gsdolmq2#
我不知道有什么魔法可以做到这一点。但是你可以使用一些额外的变量: