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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值