python replace will not replace "'" with "\'"
<pre><code>    dctLineItems = InvFunctions.dctLineItems
    for value in dctLineItems.values():
        iORDER_ID = value[0]
        iITEM_No = value[1]
        iQUANTITY = value[2]
        sTmp = value[3]
        sTmp2 = sTmp.replace("'", "\'", 1)
        #sTmp2 = connPy.escape(sTmp)
        sITEM_Name = sTmp2
        sPART_No = value[4]
        fPRICE = value[5]
        fPRICE = fPRICE.lstrip('$')
        iDOGWOOD = value[6]
        iADVANCED = value[7]
</code></pre>

<p>I have tested it extensively and replace works for just about anything except what I need it to do. When I try to replace " ' " with " \' " it doesn't do anything. Notice the commented line#8 connPy.escape(sTmp), it doesn't work either but that is going to be a separate question.</p>

<p>Another option: using Python's raw strings:</p>

<pre><code>&gt;&gt;&gt; "'hello'".replace("'", "\'")
&gt;&gt;&gt; "'hello'"
&gt;&gt;&gt;
&gt;&gt;&gt; "'hello'".replace("'", "\\'")
&gt;&gt;&gt; "\\'hello\\'"
&gt;&gt;&gt;
&gt;&gt;&gt; "'hello'".replace("'", r"\'")  # &lt;- Note the starting r
&gt;&gt;&gt; "\\'hello\\'"
</code></pre>

python