title: Understanding the Python with statement and context managers
body: <p>I am trying to understand the <code>with</code> statement. I understand that it is supposed to replace the <code>try</code>/<code>except</code> block.</p>
  <p>Now suppose I do something like this:</p>
  <pre class="lang-py prettyprint-override"><code>try:
     name = &quot;rubicon&quot; / 2  # to raise an exception
  except Exception as e:
     print(&quot;No, not possible.&quot;)
  finally:
     print(&quot;OK, I caught you.&quot;)
  </code></pre>
  <p>How do I replace this with a context manager?</p>