Jump to content


Time Import: Sleep

  • Please log in to reply
1 reply to this topic

#1 jampc3


    New Member

  • Members
  • Pip
  • 1 posts

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-u...s-loyalty.html")
text = page.read().decode("utf8")
start_of_price=where + 2
end_of_price=where + 6
return float(text[start_of_price:end_of_price])

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

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

#2 paulbarry


    Advanced Member

  • O'Reilly Author
  • PipPipPipPipPipPipPipPip
  • 306 posts

Posted 17 November 2012 - 03:39 AM

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


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users