O'Reilly Forums: Time Import: Sleep - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Time Import: Sleep Always running

#1 User is offline   jampc3 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 13-October 12

Posted 13 October 2012 - 02:04 PM

Hey all,
I'm new to programming and seem to have an issue with the "time.sleep(900)" utility. Every time I put that command in my code, it will execute, despite that it is in a "if" conditional and the condition is not met. So, my code is:

import urllib.request
import time

def get_price():
page = urllib.request.urlopen("http://www.beans-r-us.biz/prices-loyalty.html")
text = page.read().decode("utf8")
where=text.find(">$")
start_of_price=where + 2
end_of_price=where + 6
return float(text[start_of_price:end_of_price])

print("Welcome!")
price_now = input("Is the price required immediately? (Y/N)")
if price_now == "Y":
print(get_price())
else:
price = 99.99
while price > 4.74:
price = get_price()
print(price)
time.sleep(30) <---------------This guy will slow the entire program even if the price retrieved is less than 4.74
print("Buy!")

I usually check the price manually to ensure the code is working, thus I know it is not. I would appreciate some help. Thanks!
0

#2 User is offline   paulbarry 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 306
  • Joined: 20-August 09

Posted 17 November 2012 - 03:39 AM

Check that the sleep code is correctly indented under the if.

--Paul.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users