I want to cast data like [1,2,\'a\',\'He said \"what do you mean?\"\'] to a CSV-formatted string.
[1,2,\'a\',\'He said \"what do you mean?\"\']
Normally one would use csv.writer() for
csv.writer()
import csv from StringIO import StringIO with open('file.csv') as file: file = file.read() stream = StringIO(file) csv_file = csv.DictReader(stream)