title: Is it possible to have an optional with/as statement in python?
body: <p>Instead of this:</p>
  
  <pre><code>FILE = open(f)
  do_something(FILE)
  FILE.close()
  </code></pre>
  
  <p>it's better to use this:</p>
  
  <pre><code>with open(f) as FILE:
      do_something(FILE)
  </code></pre>
  
  <p>What if I have something like this?</p>
  
  <pre><code>if f is not None:
     FILE = open(f)
  else:
     FILE = None
  do_something(FILE)
  if FILE is not None:
      FILE.close()
  </code></pre>
  
  <p>Where do_something also has an "if FILE is None" clause, and still does something useful in that case - I <strong>don't</strong> want to just skip do_something if FILE is None.</p>
  
  <p>Is there a sensible way of converting this to with/as form?  Or am I just trying to solve the optional file problem in a wrong way?</p>