所以我在這里感到困惑
while self.voice_client.is_playing() == True:
self.time = 1
self.spot.clear()
for item in self.spot:
video = search(query=item)
self.query.append(video)
如何將這兩個部分結合起來?我希望它for loop與while loop. while self.item = 1, 那for item...也在運行
uj5u.com熱心網友回復:
使 for 回圈在后臺作業 while 回圈
通過對回圈的功能進行編程,將回圈的功能置于回圈for中。whilefor
一個for回圈處理一個迭代直到專案結束。專案的結尾由StopIteration導致退出for回圈的錯誤標識。
要在代碼中復制功能,請確保忽略StopIteration并繼續外回圈。
# Build for loop functionality
self_spot = ['Song_1','Song_2']
self_spot_items = iter(self_spot) # The iterable part of a for loop
count = 0 #
while True:
count = 1
# For loop functionality
try:
print(f'{next(self_spot_items)=}')
# video = search(query=item)
# self.query.append(video)
except StopIteration: # item processing done
pass # continue the while loop
# Outer loop functionlaity
print(f'{count=}')
if count > 10:
break
輸出
next(self_spot_items)='Song_1'
count=1
next(self_spot_items)='Song_2'
count=2
count=3
count=4
count=5
count=6
count=7
count=8
count=9
count=10
count=11
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/438423.html
上一篇:用于約束矩陣計算的回圈
