Created
December 28, 2010 05:25
-
-
Save zhasm/756925 to your computer and use it in GitHub Desktop.
a not very accurate timer in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import time | |
class Timer(): | |
def __init__(self): | |
self.begin=0 | |
self.secs=0 | |
def start(self): | |
self.begin=int(time()) | |
def stop(self): | |
self.secs=int(time())-self.begin | |
def __repr__(self): | |
secs=self.secs | |
result="" | |
if secs>3600: | |
result+="%d hours " % int(secs/3600) | |
secs=secs % 3600 | |
if secs>60: | |
result+="%d mins " % int (secs/60) | |
secs=secs % 60 | |
if result: | |
result+=" and %d secs, or %d secs" % ( secs, secs) | |
else: | |
result="%d seconds" % secs | |
return result | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment