Python's contextlib is a HIDDEN GEM
The purpose of contextlib is fairly evident by the name (unless you've never heard of context managers), but it has some really cool tools that I wanted to share! Plus, there's a really neat decorator trick you can achieve with it too! 00:00 - Intro 00:32 - Using @contextmanager to create context managers [1] 06:46 - Using closing to close contexts [2] 08:26 - Using suppress to suppress exceptions [3] 10:47 - Using redirect_stdout and redirect_stderr [4-5] 14:24 - Outro [1] https://docs.python.org/3/library/con... [2] https://docs.python.org/3/library/con... [3] https://docs.python.org/3/library/con... [4] https://docs.python.org/3/library/con... [5] https://docs.python.org/3/library/con... — If you want to see more of me, join my Discord server! / discord I get a lot of people asking, so here's my setup! • Visual Studio Code: • My Visual Studio Code setup! (2024) • Terminal: • Make your terminal look AMAZING • Desk/recording gear: https://kit.co/Carberra • PC build: https://uk.pcpartpicker.com/list/TmzGYN — If you have any questions, don't hesitate to ask in the comments! I'll try and answer as soon as I can, providing someone else hasn't already done so. #python #coding #howto

Partial functions in Python are SUPER NEAT

Are descriptors the most MISUNDERSTOOD part of Python?

Stop Overusing Classes in Python

Python Decorators - Visually Explained

Python 3.14: The NEW T-strings are Awesome

Expert Python Tutorial #6 - Context Managers

Python's pattern matching is EXCEPTIONAL

Generics are VITAL in typed Python

Why Your Code Isn’t Pythonic (And How to Fix It)

Python Decorators: The Complete Guide

"@contextmanager" in Python is Awesome

Python Tutorial: Context Managers - Efficiently Managing Resources

5 Useful Python Decorators (ft. Carberra)

Metaclasses in Python

The ins and outs of context managers and try-finally in Python

Building A Custom Context Manager In Python: A Closer Look

Urllib - GET Requests || Python Tutorial || Learn Python Programming

Modern Python logging

Are exception groups Python's MOST UNDERUSED feature?

