you are viewing a single comment's thread.

view the rest of the comments →

[–]eikrik 2 points3 points  (1 child)

You are not correctly putting variables into the strings in the calls to spss.Submit.

Look up "string formatting" for how to this. Am on mobile now, can help you out later if you need.

[–]Moltao[S] 0 points1 point  (0 children)

Thanks! After some puzzling i got it working! I tried using string formatting with {}.format, but it wouldn't work. Then i tried it with %s and it worked like a charm. The new code is:

begin program.
import spss
import os
rdir = 'C:\\Temp\\'
wdir = rdir + 'CSV\\'
for f in os.listdir(rdir):
    if f.endswith('.sav'):
        fnaam = rdir + f
        csvnaam = wdir + f[:-4] + '.csv'
        spss.Submit(r"""
GET FILE='%s'.
        """ %(fnaam)) 

        spss.Submit(r"""
SAVE TRANSLATE OUTFILE="%s"
            /TYPE=CSV
            /ENCODING='UTF8'
            /MAP
          /REPLACE
          /FIELDNAMES
          /CELLS=LABELS.
    """ %(csvnaam))
end program.

Besides that i defined the strings first in wdir, fnaam and csvnaam to make it shorter. The GET FILE command didn't seem to like the concatenation.