I know how to map a list to a string:
foostring = ",".join( map(str, list_of_ids) )
And I know that I can use the following to get that string into an IN clause:
cursor.execute("DELETE FROM foo.bar WHERE baz IN ('%s')" % (foostring))
What I need is to accomplish the same thing SAFELY (avoiding SQL injection) using MySQL database. In the above example because foostring is not passed as an argument to execute, it is vulnerable. I also have to quote and escape outside of the MySQL library.
(There is a related SO question, but the answers listed there either do not work for MySQL database or are vulnerable to SQL injection.)