Chapter 10, python string manipulation and with statement and context manager (10.2.1-10.2.4)------with statement and context manager (Context Manager)

Contents
10.2 with statement and context manager (Context Manager)
10.2.1 Principle of with statement constituting context manager
10.2.2 Context manager constituted by with and class 10.2.3 Context manager
constituted by with and open function
10.2.4 with A context manager composed with the decorator contextmanager

10.2 with statement and context manager (Context Manager)

       The concept of the context of the computer (Context) is similar to the context of the Chinese article (the following can be deduced from the above). The relationship between them can make corresponding follow-up reactions and processing according to the operation results.

       Significance of the context manager: The context manager has an entry and exit mechanism, can accurately allocate and release resources as needed, and can be used repeatedly to improve code reuse. The context manager is suitable for accessing resources, and the with statement is mainly to simplify code operations.

Guess you like

Origin blog.csdn.net/thefg/article/details/127993479