Hi All,

I am new to python and I am building a small program to convert CSV to SAV (SPSS file) as a self-learning project.

This is how my data looks like from the csv reader

['market,week,a1,a2,a3']
['nat,10/23/2013,9123,2983,231'
['nat,10/30/2013,2398,23,23']
['nat,11/6/2013,23,2,3'
['nat,11/13/2013,230,3,1']

Here is my code to write above data to SAV file.

#read and write data to sav file
savFileName = filename.replace('.csv', '_processed.sav')
varNames = ['MARKET', 'WEEK', 'A1', 'A2', 'A3']
varTypes = {'MARKET': 5, 'WEEK': 5, 'A1': 0, 'A2': 0, 'A3': 0}
with savReaderWriter.SavWriter(savFileName, varNames, varTypes) as writer:
for row in reader:
writer.writerow(row)

I got below error when I run the code

Traceback (most recent call last):
File "C:/Documents and Settings/DOTH01/PycharmProjects/spssconverter/main", line 38, in <module>
writer.writerow(row)
File "C:\Python27\lib\site-packages\savReaderWriter\savWriter.py", line 273, in writerow
self._pyWriterow(record)
File "C:\Python27\lib\site-packages\savReaderWriter\savWriter.py", line 296, in _pyWriterow
self.record = record
File "C:\Python27\lib\site-packages\savReaderWriter\generic.py", line 493, in record
raise TypeError(msg)
TypeError: Use ioUtf8=True to write unicode strings [pack_into expected 5 items for packing (got 1)]
I googled the error but unable to find much so would you please let me know what I need to change in my code? Also, can you give me some suggestion or how to change my code so it could be more dynamic that I dont have to hard-coded the variables name and type.

My data is fairly consistent. The first columns is always string, second is the date and everything else from the third is numeric.

Thank you very much for your input.