Which Python object can be used to create a simple context manager without defining a class?
- @contextmanager decorator
- contextlib.ExitStack()
- contextlib.AbstractContextManager()
- contextlib.contextmanager()
The contextlib.contextmanager() decorator is used to create a simple context manager without defining a class. Other options are used for different purposes related to context management.
Loading...
Related Quiz
- Which function in Python is used to read file contents as a string?
- The process of visiting all the nodes of a tree and performing an operation (such as a print operation) is called ____.
-
The Python type(_______) would return
. - What can be a potential pitfall of overusing @property decorators in a Python class?
- If a context manager's enter method raises an exception, what happens to its exit method?