Skip to content

Latest commit

 

History

History
34 lines (19 loc) · 523 Bytes

File metadata and controls

34 lines (19 loc) · 523 Bytes

Contextmanager ex

Question

Making file open function as a context manager.

Solution

.. literalinclude:: ../../languages/python/design_contextmanager_ex.py
   :language: python
   :tab-width: 4

.. runcode:: ../../languages/python/design_contextmanager_ex.py
   :language: python
   :codesite: ideone

Explanation

.. seealso::

   * :python-suggest-improve:`design_contextmanager_ex.py`
   * :python-better-explain:`design_contextmanager_ex.rst`