conditional python with
<p>I have a five or six resources that have nice 'with' handlers, and normally I'd do this:</p>

<pre><code>with res1, res2, res3, res4, res5, res6:
   do1
   do2
</code></pre>

<p>However, sometimes one or more of these resources should not be activated.  Which leads to very ugly repetitive code:</p>

<pre><code> with res1, res3, res4, res6: # these always acquired
    if res2_enabled:
        with res2:
           if res5_enabled:
               with res5:
                  do1
                  do2
           else:
              do1
              do2
     else if res5_enabled:
        with res5:
           ...
</code></pre>

<p>There must be clean easy ways to do this surely?</p>
