Which of the following is a recommended use case for custom context managers?
- Basic arithmetic calculations.
- Closing a file after reading/writing data
- Sorting a list of integers.
- Web scraping with BeautifulSoup.
A recommended use case for custom context managers is closing a file after reading or writing data. This ensures proper resource cleanup and prevents resource leaks when dealing with files.
Loading...
Related Quiz
- In Python, the _______ method is used to overload the + operator.
- How can you call a method of the parent class from within a method of a child class?
- For a property named value, the corresponding setter decorator would be _______.
- What does the finally block represent in Python's exception handling?
- Which of the following operators is a floor division in Python?