title: How to manipulate the exception in __exit__ of a context manager?
body: <p>I know it's bad style to re-raise an exception from within a context manager's <code>__exit__()</code> method. So, I'd like to tack an attribute on the instance which can carry contextual information that isn't available if I let the exception trickle through or if I catch it. This will avoid re-raising it.</p>
  
  <p>The alternative to tacking the attribute on the exception would be to swallow the exception, set some state on the instance that doubles as the context manager in question and later check that state. Problem is that this would lead to a catch 22, wouldn't it? Since the exception means that execution inside the <code>with</code> block is being exited. There is no way to repeat the operation other than entering the <code>with</code> block again, right? So the instance in which I am trying to store the contextual information would go away once the <code>__exit__()</code> method returns.</p>
  
  <p>So in short: how can I manipulate the actual exception that is pending (if it is, which I'll assume as given for this question) while in the <code>__exit__()</code> method?</p>