title: Python Replace \\ with \
body: <p>So I can't seem to figure this out... I have a string say, <code>"a\\nb"</code> and I want this to become <code>"a\nb"</code>. I've tried all the following and none seem to work;</p>
  
  <pre><code>&gt;&gt;&gt; a
  'a\\nb'
  &gt;&gt;&gt; a.replace("\\","\")
    File "&lt;stdin&gt;", line 1
      a.replace("\\","\")
                        ^
  SyntaxError: EOL while scanning string literal
  &gt;&gt;&gt; a.replace("\\",r"\")
    File "&lt;stdin&gt;", line 1
      a.replace("\\",r"\")
                         ^
  SyntaxError: EOL while scanning string literal
  &gt;&gt;&gt; a.replace("\\",r"\\")
  'a\\\\nb'
  &gt;&gt;&gt; a.replace("\\","\\")
  'a\\nb'
  </code></pre>
  
  <p>I really don't understand why the last one works, because this works fine:</p>
  
  <pre><code>&gt;&gt;&gt; a.replace("\\","%")
  'a%nb'
  </code></pre>
  
  <p>Is there something I'm missing here?</p>
  
  <p><strong>EDIT</strong> I understand that \ is an escape character. What I'm trying to do here is turn all <code>\\n</code> <code>\\t</code> etc. into <code>\n</code> <code>\t</code> etc. and replace doesn't seem to be working the way I imagined it would.</p>
  
  <pre><code>&gt;&gt;&gt; a = "a\\nb"
  &gt;&gt;&gt; b = "a\nb"
  &gt;&gt;&gt; print a
  a\nb
  &gt;&gt;&gt; print b
  a
  b
  &gt;&gt;&gt; a.replace("\\","\\")
  'a\\nb'
  &gt;&gt;&gt; a.replace("\\\\","\\")
  'a\\nb'
  </code></pre>
  
  <p>I want string a to look like string b. But replace isn't replacing slashes like I thought it would.</p>