Skip to main content

Practice ยท 1 of 2

Session Tracker

Create a class Session with __enter__ returning the string 'open' and appending 'open' to a module-level list EVENTS; __exit__ appends 'closed' and returns False. After a with block, EVENTS must be ['open', 'closed'] even if the body raises.

Difficulty: intermediate

Back to lesson: Practice: Context Manager Drills