如何解决python for循环仅更新3个变量中的2个?
我想在一个for循环中使用3个变量。 这是我尝试过的:
def loop_player_listbox():
global bol_loop,count
bol_loop = True
while True:
time.sleep(1)
str_libo_p = listbox.get(0,tk.END)
str_libo_r = listboxr.get(0,tk.END)
str_libo_price = listboxprice.get(0,tk.END)
for i,r,p in itertools.product(str_libo_p,str_libo_r,str_libo_price):
text_playername = wait.until(EC.element_to_be_clickable((By.XPATH,('/html/body/main/section/section/div[2]/div/div[2]/div/div[1]/div[1]/div[1]/div/input'))))
text_playername.click()
time.sleep(1)
text_playername.clear()
time.sleep(1)
text_playername.click()
text_playername.send_keys(i)
user_input_max_price = p
try:
choose_player = wait.until(EC.element_to_be_clickable((By.XPATH,("//span[@class='btn-text' and contains(text(),'"+i+"')]")))) and wait.until(EC.element_to_be_clickable((By.XPATH,("//span[@class='btn-subtext' and contains(text(),'"+r+"')]"))))
choose_player.click()
count = 0
while count < 5:
while True:
# some unimportant code
# set speed
# some unimportant code
# set max BIN price
while True:
#user_input_max_price = input('Enter max buy now price (>250):')
user_input_max_price = p
if user_input_max_price.isdigit():
int_user_input_max_price = int(user_input_max_price)
if int_user_input_max_price > 250:
break
else:
print('Max buy now price must be >250')
continue
else:
continue
# set max price
# some unimportant code
# Buy until 100 players were bought
while count < 5:
# some unimportant code
count +=1
问题是,变量r
和p
确实在count = 5
之后更新。
但是i
始终仅显示列表框中的第一项,并且不会更新。每次我的循环返回到行for i,p ...
时,我在调试中都会看到只有变量r
和p
被更新。
我不知道为什么。在寻找如何组合多个for
循环时,我发现了itertools
,所以我使用了它。
也许有人看到错了?
解决方法
从itertools更改为zip,解决了该问题。
for i,r,p in zip(str_libo_p,str_libo_r,str_libo_price):
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。