【发布时间】:2013-03-25 01:47:18
【问题描述】:
我正在尝试连续运行 WHILE 循环以每十五分钟检查一次条件。当使用 time.sleep(900) 时,它最初会推迟执行 WHILE 循环十五分钟,然后在满足条件后停止运行。
我相信 Python 2 出于这个原因使用了这个功能,Python 3.3 不再遵循这个功能了吗?如果不是,即使条件已经满足,我如何无限期地运行一个while循环?
下面是我当前代码的 sn-p:
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)
【问题讨论】:
-
更新了您的问题以包含原始代码以防止任何混淆。 :)
标签: python python-3.x