Puzzle 20: Explanation
Let’s learn how context managers work when using a with statement.
We'll cover the following...
Try it yourself
Try executing the code below to verify the results:
Press + to interact
class timer:def __init__(self, name):self.name = namedef __enter__(self):...def __exit__(self, exc_type, exc_value, traceback):result = 'OK' if exc_type is None else 'ERROR'print(f'{self.name} - {result}')return Truewith timer('div'):1 / 0