title: python: how to escape slashes in path?
body: <pre><code>temp_dir = 'spam'
  dir_name = 'foo/bar/baz.xyz'  # should be escaped somehow
  dir = os.path.join(temp_dir, dir_name)
  os.mkdir(dir)
  </code></pre>
  
  <p>I need to create directory inside <code>temp_dir</code> with name <code>dir_name</code>. But current code will produce 3 nested dirs inside <code>temp_dir</code>.</p>
  
  <p>I've tried to replace each slash in <code>dir_name</code> with <code>\/</code> but <code>os.mkdir</code> ignores escaping with <code>\</code> and treat it as part of nested dir name.</p>