The following code writes a CSV file in UTF-8 format. The csv file is stored in the filesystem.
with open('sample.csv', 'w', newline='', encoding='utf-8') as csvfile:
spamwriter = csv.writer(csvfile, delimiter=' ',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
csvfile.write('\ufeff')
spamwriter.writerow("嗨")
Now I don't want to write to the fileystem anymore, I only want to store the CVS into a StringIO buffer. How should I do this?