Context Managers help you make code easier to read while making sure that all your resources are cleaned up properly. In this video, we dive into contextlib, that providers some amazing tools to create context managers, as well as providing some very useful context managers right out of the box.
00:00 Introduction
00:12 What context managers do
00:37 The contextmanager decorator
02:08 Using classes to create context managers
03:11 Using ContextDecorator
03:51 Using the ExitStack to open files simultaneously
04:39 Using suppress to suppress Exceptions
05:17 Using ExitStack with conditions
07:32 Redirecting console output with redirect_stdout
Links:
- Download PyCharm: https://jb.gg/u8syo9