title: Several `with`s in `try`s
body: <p>I have several possible files which could hold my data; they can be compressed in different ways, so to open them I need to use <code>file()</code>, <code>gzip.GzipFile()</code> and other which also return a file object (supporting the <code>with</code> interface).</p>
  
  <p>I want to try each of them until one succeeds in opening, so I could do something like</p>
  
  <pre><code>try:
    with gzip.GzipFile(fn + '.gz') as f:
      result = process(f)
  except (IOError, MaybeSomeGzipExceptions):
    try:
      with xCompressLib.xCompressFile(fn + '.x') as f:
        result = process(f)
    except (IOError, MaybeSomeXCompressExceptions):
      try:
        with file(fn) as f:
          result = process(f)
      except IOError:
        result = "some default value"
  </code></pre>
  
  <p>which obviously isn't feasible in case I have dozens of possible compression variants.  (The nesting will get deeper and deeper, the code always looking very much alike.)</p>
  
  <p>Is there a nicer way to spell this out?</p>
  
  <p>EDIT: If possible I'd like to have the <code>process(f)</code> out of the try/except as well to avoid accidental catching of exceptions raised in the <code>process(f)</code>.</p>