How would you make a comma-separated string from a list of strings?
lambda magic? Doesn't this work?
'a', 'b', 'c']print(','.join(foo))a,b,cprint(','.join())print(','.join(['a']))afoo = [
In case if there are numbers in the list, you could use list comprehension:
','.join([str(x) for x in foo])
or a generator expression:
','.join(str(x) for x in foo)
",".join(l) will not work for all cases. I'd suggest using the csv module with StringIO
import StringIOimport csvl = ['list','of','["""crazy"quotes"and\'',123,'other things']line = StringIO.StringIO()writer = csv.writer(line)writer.writerow(l)csvcontent = line.getvalue()# 'list,of,"[""""""crazy""quotes""and\'",123,other things\r\n'