Sobes.tech
Junior — Senior

Context manager for measuring duration

livecode

Task condition

Create a Timer class that implements the context manager protocol. When entering the with block, start measuring time, and when exiting, store the measured time in the elapsed field of the instance.

with Timer() as timer:
    time.sleep(1)

print(timer.elapsed)