title: How to escape quotation marks when initializing a unix/shell command in python?
body: <p>I am using target.write command to write this line</p>
  
  <pre><code>line4 = "do echo "$i|$( geoiplookup -f /usr/share/GeoIP/GeoIP.dat $i | cut -d' ' -f4 -n | sed -e 's/,$//' -e '/^$/d' )" &gt;&gt; $output;".format(name)
  </code></pre>
  
  <p>but i face the error :</p>
  
  <pre><code>  File "m.py", line 8
      target.write('output=/var/www/html/Result/{0}/RIPs.txt;\necho &gt; $output;\nfor i in $( cat /var/www/html/Result/{0}/PWIPs.txt );\ndo echo "$i|$( geoiplookup -f /usr/share/GeoIP/GeoIP.dat $i | cut -d' ' -f4 -n | sed -e 's/,$//' -e '/^$/d' )" &gt;&gt; $output;;\ndone'.format(name))
                                                                                                                                                                                                                                ^
  SyntaxError: invalid syntax
  </code></pre>
  
  <p>Also i removed the code </p>
  
  <pre><code>| sed -e 's/,$//' -e '/^$/d'
  </code></pre>
  
  <p>but i got the the file without the ' strings after -d ?</p>
  
  <p>any help ?</p>
  
  <p>Thanks</p>