title: Escaping characters in python just once (single backlash)
body: <p>I want to escape a string from this:</p>
  
  <pre><code>str1 = "this is a string (with parentheses)"
  </code></pre>
  
  <p>to this:</p>
  
  <pre><code>str2 = "this is a string \(with parentheses\)"
  </code></pre>
  
  <p>That is, a single <code>\</code> escape character at the parentheses. This is to be fed to another client which needs to escape these characters and will only work with a single escaping slash.</p>
  
  <p>For simplicity I focus below on the opening parentheses only, i.e. changing from <code>'('</code> to <code>'\('</code>
  So far I tried:</p>
  
  <ol>
  <li><p>replace</p>
  
  <pre><code>str1.replace("(", "\(")
  'this is a string \\(with parentheses)'
  </code></pre></li>
  <li><p>sub</p>
  
  <pre><code>re.sub( "\(", "\(", str1)
  'this is a string \\(with parentheses)'
  </code></pre></li>
  <li><p>Escape dictionary with raw string</p>
  
  <pre><code>escape_dict = { '(':r'\('}
  "".join([escape_dict.get(char,char) for char in str1])
  'this is a string \\(with parentheses)'
  </code></pre></li>
  </ol>
  
  <p>Whatever the case I always get double backlash. Is there a way to get only one?</p>