title: creating an exception while opening a directory
body: <p>I encountered a problem while opening a directory. I loop over all directories and I walk in:</p>
  
  <pre><code>for i in var1:
          for j in var2:
                  if i == j: continue
                        sdir = i+'_'+j
                        os.chdir("/home/Documents/test"+sdir) 
  </code></pre>
  
  <p>Everything works fine as long as there is a directory according to the name <code>sdir</code>. When it doesn't exist, the following error is thrown:</p>
  
  <blockquote>
    <p>OSError: [Errno 2] No such file or directory: /home/Documents/test/a_b</p>
  </blockquote>
  
  <p>However I have a directory named <code>b_a</code>. Therefore I want to swap <code>i</code> and <code>j</code> in my code. I mean if there is no <code>a_b</code> directory -> swap <code>a</code> and <code>b</code> -> go in the <code>b_a</code> directory.</p>
  
  <p>How may I do an exception using <code>os.chdir("/home/Documents/test/"+sdir)</code>?</p>