python timesleep函数_Python 3.3中的time.sleep()函数?
我试着每隔15分钟连续运行一个WHILE循环来检查一个条件。当使用time.sleep(900)时,它会延迟执行WHILE循环15分钟,然后在满足条件后停止运行。
我相信Python2之所以使用这个函数是因为这个原因,Python3.3是否不再遵循这个原则了?如果没有,我将如何无限期地运行一个while循环,即使条件已经满足?
下面是我当前的代码片段:if price_now == 'Y':
print(get_price())
else:
price = "99.99"
while price > "7.74":
price = get_price()
time.sleep(5)
编辑:根据eandersson反馈更新。if price_now == 'Y':
print(get_price())
else:
price = 99.99
while price > 7.74:
price = get_price()
time.sleep(5)
get_price()函数:def get_price():
page = urllib.request.urlopen("link redacted")
text = page.read().decode("utf8")
where = text.find('>$')
start_of_price = where + 2
end_of_price = start_of_price + 4
price = float(text[start_of_price:end_of_price])
return(price)