56
- I have a list of dictionaries containing unicode strings.
csv.DictWritercan write a list of dictionaries into a CSV file.- I want the CSV file to be encoded in UTF8.
- The
csvmodule cannot handle converting unicode strings into UTF8. The
csvmodule documentation has an example for converting everything to UTF8:def utf_8_encoder(unicode_csv_data): for line in unicode_csv_data: yield line.encode('utf-8')It also has a
UnicodeWriterclass.
But... how do I make DictWriter work with these? Wouldn't they have to inject themselves in the middle of it, to catch the disassembled dictionaries and encode them before it writes them to the file? I don't get it.