Thread: Sleep function

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Sleep function


    Hello, i'm a middle school student making a python program for a class.
    Code:
    import time
    
    print("Rock, Paper, and Scissors in Python")
    print("Made by ")
    def wait(secs):
        time.sleep(secs)
    wait(3)
    print("Type in your choice: Rock, Paper or Scissors")
    I am using the sleep function, but it sleeps at the beginning before the first print function happens, and then prints everything else at the same time. I am using wing ide. Any help?

    Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Posts
    506
    Rep Power
    33
    Works fine for me. Try sys.stdout.flush() to flush the print buffer.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by dwblas
    Works fine for me. Try sys.stdout.flush() to flush the print buffer.
    Where would i put this?
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,889
    Rep Power
    481
    flush the output file when you need it synchronized with your program logic. (Immediately before wait(3) statement.)

    sys.stdout is line buffered---that is it flushes after each new line. At least it is on my system, and on dwblas's as well.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0
    hmm, doesn't seem to work. Do you think it is my program i am using? I am using Wingware Ide
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,889
    Rep Power
    481
    Maybe Wingware causes the problem. I normally run python in an emacs shell buffer, occasionally in idle, and once in a while in xterm or similar terminal window if I need to test my console control. I never used Wingware.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo