title: Verify directory write privileges
body: <p>I am writing a program in Python 2.7 that retrieves remote files and dumps them in a directory that can be specified by the user. Currently, in order to verify that the program can in fact write to that directory, I do the following (assuming that dumpdir is a string containing the name of the directory to check):</p>
  
  <pre><code>try:
      os.mkdir(dumpdir+'/.mwcrawler')
      os.rmdir(dumpdir+'/.mwcrawler')
  except:
      logging.error('Could not open %s for writing, using default', dumpdir)
  </code></pre>
  
  <p>But this feels even more hackish than my usual code. What's the correct way to go about this? Maybe some sort of assertion on privileges?</p>