jmunsch

Python: count down timer in place using stdout

Sep 9th, 2014
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.25 KB | None | 0 0
  1. import time, sys
  2.  
  3. def countdown(seconds):
  4.  
  5.     for sec in xrange(0,Seconds):
  6.         sys.stdout.flush()
  7.         sys.stdout.write('\r'+str(sec))
  8.         time.sleep(1)
  9.     sys.stdout.write('\n')
  10.     return
  11.  
  12. s = 60
  13. countdown(s)
  14. print("Done")
Advertisement
Add Comment
Please, Sign In to add comment