title: sed command in Python using json.dumps of a quoted string does not keep the single quote
body: <p>Sorry if the title is little bit convoluted... An example will show better what I mean:</p>
  
  <p>I have a text file named foo that contains the string 'bar'.</p>
  
  <p>In Python, I have a dictionary :</p>
  
  <pre><code>d = {"key": "item['id']"}
  </code></pre>
  
  <p>I want to replace the string bar in my file with a json dump of my dictionary. Commands:</p>
  
  <pre><code>import subprocess
  subprocess.call("sed 's#bar#%s#g' foo &gt; foo2" % json.dumps(d),shell=True)
  </code></pre>
  
  <p>When I cat the file foo2, result is:</p>
  
  <pre><code>&gt; cat foo2
  {"key": "item[id]"}
  
  </code></pre>
  
  <p>Problem is: the single quotes are lost around id. How can I avoid that?</p>