The ins and outs of context managers and try-finally in Python
mCoding
You can't forget!
Context managers (used with the "with" statement) and try-finally are both constructs in Python that help you ensure certain cleanup code runs even in the presence of exceptions. Becoming familiar with these constructs is important for developing good coding habits in Python. Don't put the burden of remembering how to do cleanup on yourself, use a context manager to let the object handle its own cleanup! In this video, we take a deep dive into the semantics of context managers and try-finally, including the basic examples, sharp corners (and how to avoid them!), as well as less common use-cases.
― mCoding with James Murphy (https://mcoding.io)
Source code: https://github.com/mCodingLLC/VideosSampleCode
With statement docs: https://docs.python.org/3/reference/datamodel.html#with-statement-context-managers
Try-finally docs: https://docs.python.org/3/reference/compound_stmts.html#finally-clause
Pythonizing Imgui video: https://www.youtube.com/watch?v=wh_W-veFpKU
SUPPORT ME ⭐
---------------------------------------------------
Sign up on Patreon to get your donor role and early access to videos!
https://patreon.com/mCoding
Feeling generous but don't have a...
Context managers (used with the "with" statement) and try-finally are both constructs in Python that help you ensure certain cleanup code runs even in the presence of exceptions. Becoming familiar with these constructs is important for developing good coding habits in Python. Don't put the burden of remembering how to do cleanup on yourself, use a context manager to let the object handle its own cleanup! In this video, we take a deep dive into the semantics of context managers and try-finally, including the basic examples, sharp corners (and how to avoid them!), as well as less common use-cases.
― mCoding with James Murphy (https://mcoding.io)
Source code: https://github.com/mCodingLLC/VideosSampleCode
With statement docs: https://docs.python.org/3/reference/datamodel.html#with-statement-context-managers
Try-finally docs: https://docs.python.org/3/reference/compound_stmts.html#finally-clause
Pythonizing Imgui video: https://www.youtube.com/watch?v=wh_W-veFpKU
SUPPORT ME ⭐
---------------------------------------------------
Sign up on Patreon to get your donor role and early access to videos!
https://patreon.com/mCoding
Feeling generous but don't have a...
0 Comments
No comments yet. Be the first to weigh in.