title: Replace all quotes in a string with escaped quotes?
body: <p>Given a string in python, such as:</p>
  
  <pre><code>s = 'This sentence has some "quotes" in it\n'
  </code></pre>
  
  <p>I want to create a new copy of that string with any quotes escaped (for further use in Javascript). So, for example, what I want is to produce this:</p>
  
  <pre><code>'This sentence has some \"quotes\" in it\n'
  </code></pre>
  
  <p>I tried using <code>replace()</code>, such as:</p>
  
  <pre><code>s.replace('"', '\"')
  </code></pre>
  
  <p>but that returns the same string. So then I tried this:</p>
  
  <pre><code>s.replace('"', '\\"')
  </code></pre>
  
  <p>but that returns double-escaped quotes, such as:</p>
  
  <pre><code>'This sentence has some \\"quotes\\" in it.\n'
  </code></pre>
  
  <p>How to replace <code>"</code> with <code>\"</code>?</p>
  
  <p>UPDATE:</p>
  
  <p>I need as output from this copyable text that shows both the quotes and the newlines as escaped.  In other words, I want to be able to copy:</p>
  
  <pre><code>'This sentence has some \"quotes\" in it.\n'
  </code></pre>
  
  <p>If I use the raw string and <code>print</code> the result I get the correctly escaped quote, but the escaped newline doesn't print. If I don't use <code>print</code> then I get my newlines but double-escaped quotes. How can I create a string I can copy that shows both newline and quote escaped?</p>