Context Managers: Intro & Overview
In this first lesson of the course, you’ll get an overview about the courses content as well as a brief introduction into the basic concepts of context managers.
Furthermore, Python’s with
-statements role is revealed.
00:00
Hey there! This is Dan. Today I’m going to talk about the with
statement in Python. The with
statement relates to something that is called context managers, and it is sometimes regarded as a bit of an obscure feature by some people, but actually, when you peek behind the scenes there’s relatively little magic involved and it’s actually a highly useful feature that can help you write cleaner and easier-to-understand, easier-to-maintain code. So, the first question that I want to talk about is, “Okay, so what is the with
statement actually good for?”
00:36
The with
statement is great for simplifying some of the common resource management patterns that you’ll see in your code. So, by resources in this case, I mean system resources, like files, locks, or some kind of network connection—stuff like that.
00:54
And so with the with
statement, you can abstract away some of the functionality there that is commonly required, like dealing with the acquisition and releasing these resources again.
Become a Member to join the conversation.