I want to create a CSV string which is being sent by mail. I'd like to avoid temporary files because it's just not necessary for me to deal with the file system. As I said, the data is passed to a mail class.
I found this neat solution
output = io.StringIO()
writer = csv.writer(output, delimiter=';', dialect='excel-tab')
writer.writerows(data)
It works perfectly except that it creates a UTF-8 file which will have messed up special characters if you open it in Excel.
I tried to pass a BOM to the StringIO
constructor, but nothing worked:
output = io.StringIO('\ufeff')
I tried to somehow set the encoding to utf-8-sig
but I couldn't find a way except using a file...
Any ideas how to solve this problem?
Thanks!