In SPSS, using python, I am writing a list of lists into a csv file:
begin program.
import spss,spssaux, sys, csv, codecs
def WriteDim():
MyArray=[some list of lists]
for MyVar in MyFile.varlist:
MyArray.append([MyVar.name,MyVar.label])
DimFile="DimCSV.csv"
with codecs.open(DimFile, "w",encoding='utf8') as output:
writer = csv.writer(output, lineterminator='\n')
writer.writerows(MyArray)
end program.
I have some Spanish text in my practice array, for example "reparación"
. If I open the output file in a text editor, all looks fine. However, if I open it in Excel 2016, it looks like this: "reparación"
. I would need to go to Data/Import From text" and manually choose UTF encoding, but this is not an option for the future users of my SPSS program.
Is there any way of writing the file so that Excel will open it using UTF-8 encoding ? It has to be a csv file - opening it in excel is only one use of it.