Content deleted Content added
move code example comment different line |
|||
Line 55:
</source>
Similarly, the [[Python (programming language)|Python]] language has a <code>with</code> statement can be used to similar effect with a ''context manager'' object. The ''context manager protocol'' implies implementing <code>__enter__</code> and <code>__exit__</code> methods which get automatically called by the <code>with</code> statement construct to facilitate not needing exception handling clauses such as <code>finally</code> to cleanup resource allocations, etc. (see PEP 343):
<source lang="python">
with
# Perform actions with the resource.
...
# Perform other actions where the resource is guaranteed to be deallocated.
...
</source>
|