如某值为"ABC"D
由于mysql中可用\当转义符
因此查询语句应该为select * from table where colname = "\"ABC\"D"
因此在python中的查询语句应该为
cur.execute( 'select * from table where colname = "\"ABC\"D" ')
如果此时用变量a来表示
即a = "ABC"D
则应用replace对a中的 " 进行转义
即a.replace(' " ' , '\\" ')
在"前加上\
查询语句变为
cur.execute( 'select * from table where colname = "%s" ' %a)