我正在做的事情,需要使它的方式,通过几个层次的检查,如果条件得到满足,要么一起退出,要么设置某些变量,然后开始循环。我的问题围绕着如何从内部for循环跳回主while循环。在
while True:
message = stomp.get
message = simplejson.loads(message.body)
if message[0]['fieldname1'] == False:
global ShutdownState
ShutdownState = True
break # Should leave the While loop all together
else:
for item in message[0]['fieldname2'][0]['fieldname2-1']
if item['fieldname2-1-1'] == True:
list1_new[len(list_new):] = [item['fieldname2-1-2']
list1-state = set(list1) == set(list1_new)
if list1-state == True:
continue # should reset the while loop
else:
list1 = list1_new # should print the new list1 and then reset the while loop
print list1
continue
现在还不清楚示例代码是要代表整个循环,还是只是它的开始。如果这是全部,那么有很多方法可以重组它。这里是第一步(注意代码中有一些拼写错误(例如,},诸如此类),所以我不得不调整一些东西。您需要检查它是否仍然与原始代码匹配。(有关查找列表中第一个元素的实现的更多信息,以及一些替代方法,请查看Python: Find in list。)
list1-state
而不是{您也可以通过使其成为do while循环来清理这个问题,但这是一个不太重要的因素。基于Emulate a do-while loop in Python?,可以执行以下操作:
^{pr2}$相关问题 更多 >
编程相关推荐