Objective
Create a Python program with a class that is a context manager: an object that can be used with with thanks to the __enter__ and __exit__ methods.
Instructions
- Create the class
Sectionwith a constructor that receives and stores a name. __enter__must showEntering: nameand return the object itself.__exit__must showLeaving: nameand returnFalse.- Read an integer
nand thennnames. For each name use awithblock with the class and, inside it, showLength: kwith the length of the name.
2
ana
luis
Entering: ana
Length: 3
Leaving: ana
Entering: luis
Length: 4
Leaving: luis
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise