title: how to insert \ backslash before quotes in string python
body: <p>I want to insert a \ before each quotes in my string to insert it to my SQL database using pymysql. If I don't escape quotes I can not insert strings in my database.</p>
  
  <p>For exemple: </p>
  
  <blockquote>
    <p>str = "ok I'm ready"</p>
  </blockquote>
  
  <p>must be :</p>
  
  <blockquote>
    <p>str = "ok I\'m ready"</p>
    
    <p>but print str must be : "ok I'm ready"</p>
  </blockquote>
  
  <p>To perform it I have done:</p>
  
  <pre><code>str = str.replace("'", "\'")
  </code></pre>
  
  <p>But it's not working and I still can not insert my string in my database. I have the error message :</p>
  
  <blockquote>
    <p>(1064, u"You have an error in your SQL syntax; check the manual that
    corresponds to your MySQL server version for the right syntax to use
    near 's Semantic Search software can power everything from intuitive
    chatbots to searc' at line 1"): ProgrammingError Traceback (most
    recent call last): File "/var/task/setter_organizations.py", line 38,
    in handler structured_data.insert() File
    "/var/task/setter_organizations.py", line 107, in insert
    self.rds.insertItem(self.type, self.data) File "/var/task/RDS/rds.py",
    line 92, in insertItem return self.insert(req) File
    "/var/task/RDS/rds.py", line 35, in insert affected_rows =
    self.cursor.execute(request) File "/var/task/RDS/pymysql/cursors.py",
    line 166, in execute result = self._query(query) File
    "/var/task/RDS/pymysql/cursors.py", line 322, in _query conn.query(q)
    File "/var/task/RDS/pymysql/connections.py", line 856, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
    File "/var/task/RDS/pymysql/connections.py", line 1057, in
    _read_query_result result.read() File "/var/task/RDS/pymysql/connections.py", line 1340, in read
    first_packet = self.connection._read_packet() File
    "/var/task/RDS/pymysql/connections.py", line 1014, in _read_packet
    packet.check_error() File "/var/task/RDS/pymysql/connections.py", line
    393, in check_error err.raise_mysql_exception(self._data) File
    "/var/task/RDS/pymysql/err.py", line 107, in raise_mysql_exception
    raise errorclass(errno, errval) ProgrammingError: (1064, u"You have an
    error in your SQL syntax; check the manual that corresponds to your
    MySQL server version for the right syntax to use near 's Semantic
    Search software can power everything from intuitive chatbots to searc'
    at line 1")</p>
  </blockquote>
  
  <p>I also would print my string and don't see the \</p>
  
  <p>Does anyone know how can I do ?</p>