title: How to get an absolute file path in Python? (Get rid of backslashes)
body: <p>Given a path such as &quot;mydir/myfile.txt&quot;, how do I find the file's absolute path relative to the current working directory in Python? E.g. on Windows, I might end up with:</p>
  <p><code>&quot;C:/example/cwd/mydir/myfile.txt&quot;</code>.</p>
  <p>I tried: <code>mypath = os.path.abspath(&quot;../mydir/myfile.txt&quot;)</code>. But I got:</p>
  <pre class="lang-py prettyprint-override"><code>&gt;&gt; print(mypath)
  C:\example\cwd\mydir\myfile.txt
  </code></pre>
  <p>Note that when I execute <code>mypath</code> I have <code>C:\\example\\cwd\\mydir\\myfile.txt</code>.</p>