Johz

Clock class

Jul 6th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. import time
  2.  
  3. class Clock(object):
  4.     def __init__(self):
  5.         self.myTime = time.time()
  6.     def tick(self, secs=1):
  7.         while time.time() <= secs + self.myTime:
  8.             pass
  9.         self.myTime = time.time()
  10.  
  11. def main():
  12.     myClock = Clock()
  13.     for i in xrange(10):
  14.         z = time.time()
  15.         print z,'\t', i*0.25,
  16.         time.sleep(i*0.25)
  17.         myClock.tick()
  18.         print '\t', time.time(), '\t', time.time() - z
  19.  
  20. if __name__ == '__main__':
  21.     main()
Advertisement
Add Comment
Please, Sign In to add comment