contextlib.nullcontext (enter_result = None)
enter_result - The result to be passed to as.
The resulting context manager does nothing but return from its __enter__ ( ) what was passed to the function as an argument.
This can be useful if you are using a context manager, which is optional, depending on the circumstances.
from contextlib import nullcontext, contextmanager
def my_manager ():
def maybe_managed (manage):
manager = my_manager () if manage else nullcontext ('not managed')
with manager as managed:
maybe_managed (True) # managed
maybe_managed (False) # not managed
A Practical Approach to Computer Algorithms Using Python® and C# Rod Stephens started out as a mathematician, but while studying at MIT, he discovered how much fun algorithms are. He took every al...
Cracking the Coding Interview PDF: 189 Programming Questions and Solutions, 6th Edition. I am not a recruiter. I am a software engineer. And as such, I know what it's like to be asked to create ing...
Shabbir Challawala has over 8 years of rich experience in providing solutions based on MySQL and PHP technologies. He is currently working with KNOWARTH Technologies. He has worked in various PHP-base...
Learn how data literacy is changing the world and giving you a better understanding of life's biggest problems in this "Important and Comprehensive" Guide to Statistical Thinking (New York). The bi...