Python String Formats with SQL Wildcards and LIKE

后端 未结 6 914
情深已故
情深已故 2020-11-30 11:04

I\'m having a hard time getting some sql in python to correctly go through MySQLdb. It\'s pythons string formatting that is killing me.

My sql statement is using the

6条回答
  •  不知归路
    2020-11-30 11:51

    To escape ampersands in Python string formatting expressions, double the ampersand:

    '%%%s%%' % search_string
    

    Edit: But I definitely agree with another answer. Direct string substitution in SQL queries is almost always a bad idea.

提交回复
热议问题