I am trying to write characters with double dots (umlauts) such as ä, ö and Ö. I am able to write it to the file with data.encode(\"utf-8\") but the result
data.encode(\"utf-8\")
Add a parameter encoding to the open() and set it to 'utf8'.
encoding
open()
'utf8'
import csv data = "ääÖ" with open("test.csv", 'w', encoding='utf8') as fp: a = csv.writer(fp, delimiter=";") a.writerows(data)
Edit: Removed the use of io library as open is same as io.open in Python 3.
io
open
io.open