import time
class Duration:
def __init__(self, description):
self.description = description
def __enter__(self):
self.start = time.time()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.end = time.time()
self.duration = self.end - self.start
print(self.description,end=" ")
print("took {} seconds.".format(self.duration))