Last active
August 29, 2015 14:07
-
-
Save embayer/9baba71576e09c839265 to your computer and use it in GitHub Desktop.
print a duration in human readable format
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
import datetime | |
import time | |
class Duration: | |
def __init__(self, start_time=None, end_time=None): | |
self.start_time = start_time | |
self.end_time = end_time | |
def start(self): | |
self.start_time = time.time() | |
def stop(self): | |
self.end_time = time.time() | |
def print_duration(self): | |
duration = self.end_time - self.start_time | |
print str(datetime.timedelta(seconds=int(duration))) | |
d = Duration() | |
d.start() | |
time.sleep(3) | |
d.stop() | |
d.print_duration() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment