Python Context Manager Example: Timer

What is Context Manager in Python

It is something to force your python objects, function or class to do something before/after your original manipulation.

How to Implement a Context Manager?

Implement the "dunder"s ("magic" objects or attributes) __enter__ and __exit__.

Timer is a Good Example

Because a timer should always start at the execution of something and stop immediately when the execution completed. This is useful for making a benchmark of time when profiling the implementation of your function.