title: Creating a relative symlink in python without using os.chdir()
body: <p>Say I have a path to a file:</p>
  
  <pre><code>/path/to/some/directory/file.ext
  </code></pre>
  
  <p>In python, I'd like to create a symlink in the same directory as the file, that
  points to the file.  I'd like to end up with this:</p>
  
  <pre><code>/path/to/some/directory/symlink -&gt; file.ext
  </code></pre>
  
  <p>I can do this fairly easily using os.chdir() to cd into the directory and
  create the symlinks.  But os.chdir() is not thread safe, so I'd like to avoid
  using it.  Assuming that the current working directory of the process is not
  the directory with the file (os.getcwd() != '/path/to/some/directory'),
  what's the best way to do this?</p>
  
  <p>I guess I could create a busted link in whatever directory I'm in, then
  move it to the directory with the file:</p>
  
  <pre><code>import os, shutil
  os.symlink('file.ext', 'symlink')
  shutil.move('symlink', '/path/to/some/directory/.')
  </code></pre>
  
  <p>Is there a better way to do this?</p>
  
  <p><strong>Note, I don't want to end up with is this:</strong></p>
  
  <pre><code>/path/to/some/directory/symlink -&gt; /path/to/some/directory/file.ext
  </code></pre>