Context Managers and Python's with Statement

In a Deep Dive course Part II by Fred Baptiste I learned about Context Manager in Python. However, I wanted to get a deeper understanding of the subject. Therefore, I took an additional tutorial on this subject. I completed the intermediate-level tutorial “Context Managers and Python's with Statement” by Leodanis Pozo Ramnos at Real Python. In this tutorial I learned about: • The try … finally Approach • The with Statement Approach • Working With Files • Traversing Directories • Performing High-Precision Calculations • Using Python with Statement: Handling Locks in Multithreaded Programs • Using Python with Statement: Testing for Exceptions With pytest • Using the async with Statement • How to use Context Manager Protocol • Creating Custom Context Managers • Coding Class-Based Context Managers • Writing a Sample Class-Based Context Manager • Handling Exceptions in a Context Manager • Opening Files for Writing: First Version • Redirecting the Standard Output • Measuring Execution Time • Creating Function-Based Context Managers • Opening Files for Writing: Second Version • Mocking the Time • Writing Good APIs With Context Managers • Creating an Asynchronous Context Manager You can find this tutorial at https://realpython.com/python-with-statement/

Our Sidebar

You can put any information here you'd like.

  • Latest Posts
  • Announcements
  • Calendars
  • etc