Turn A Mixed List Into A String, Keep Quotes Only For Strings
I would like to go from this list: my_list = [u'a','b','c',1,2,3] ...to this string, which maintains the quotes (for creating a sql statement): my_string = ''a', 'b', 'c', 1, 2, 3
Solution 1:
disclaimer: you should NOT be preparing SQL using plain string manipulation! use a library appropriate for the database you are using to prepare statements.
for your edification (note this doesn't properly format unicode literals, you can feel free to replace repr
with a function with a special case for unicode):
my_string = ', '.join(repr(x) for x in my_list)
Post a Comment for "Turn A Mixed List Into A String, Keep Quotes Only For Strings"